From d59b5b6678400888ec9c7efdc2f2e267f42ed413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 2 Jan 2024 02:04:18 +0100 Subject: [PATCH 001/159] minor readme fix --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7c18360f..b84481f3 100755 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ request through the asynchronous processing framework that is part of the crm-pl The framework depends on two custom metadata objects in order to dynamically instruct the application how to handle the message payload. -### AsyncRequestHandlerBinding_mdt +### `AsyncRequestHandlerBinding_mdt` Binding between the asynchronous processing request (`AsyncRequest__c`) type created by this package and the `KafkaMessageAsyncJob` class in order to instruct the asynchronous processing framework to call the `KafkaMessageAsyncJob` class in order to handle @@ -16,21 +16,21 @@ requests originating from this package. ### KafkaMessageHandlerBinding_mdt -Binding between the KafkaMessage**c.Topic**c field and an Apex handler class for a given Topic in order to instruct the +Binding between the `KafkaMessage__c.Topic__c` field and an Apex handler class for a given Topic in order to instruct the application on how to handle a message payload related to a specific Kafka topic. ## Execution Flow 1. An external application inserts a record or batch or records into the KafkaMessage\_\_c sObject -2. A trigger on the KafkaMessage**c object insert one record into the AsyncRequest**c object for each batch of up to 200 +2. A trigger on the KafkaMessage__c object insert one record into the AsyncRequest__c object for each batch of up to 200 KafkaMessage\_\_c records created in a single transaction, representing a a request for asynchronous processing of the new messages. 3. When the asynchronous processing framework processes the request, the custom metadata binding `AsyncRequestHandlerBinding_mdt` - instructs the application to handle the request using the `KafkaMessageAsyncJob` Apex class. - If no `AsyncRequestHandlerBinding_mdt` record is found corresponding to the "Kafka Message" AsyncRequestType**c value, - the `AsyncRequest**c` record is updated with an error. -4. The `KafkaMessageAsyncJob` queries for the relevant KafkaMessage**c records by the Ids stored in the async processing - request and queries the `KafkaMessageHandlerBinding_mdt` custom metadata object for registered bindings between `KafkaMessage**c.Topic**c` - values and corresponding Apex classes to handle payloads corresponding to Topic**c values. - If no `KafkaMessageHandlerBinding_mdt` record is found corresponding to the `Topic__c` value, the relevant + instructs the application to handle the request using the `KafkaMessageAsyncJob` Apex class. - If no `AsyncRequestHandlerBinding_mdt` record is found corresponding to the "Kafka Message" AsyncRequestType__c value, + the `AsyncRequest__c` record is updated with an error. +4. The `KafkaMessageAsyncJob` queries for the relevant KafkaMessage__c records by the Ids stored in the async processing + request and queries the `KafkaMessageHandlerBinding_mdt` custom metadata object for registered bindings between `KafkaMessage__c.Topic__c` + values and corresponding Apex classes to handle payloads corresponding to Topic__c values. - If no `KafkaMessageHandlerBinding_mdt` record is found corresponding to the `Topic__c` value, the relevant `KafkaMessage__c` record is updated with an error. The message kan then be retried after the error has been addressed. 5. The Apex class registered by the `KafkaMessageHandlerBinding_mdt` binding executes the business logic corresponding to the `Topic__c` value. - If an execption occurs, the relevant`KafkaMessage__c` record is updated with an error. The message kan then be retried From 86c73401749d9a4648dec9908bb768052bd44ecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 2 Jan 2024 02:04:28 +0100 Subject: [PATCH 002/159] add a little test data for new pdl and gt topics --- dummy-data/ManageTestData.apex | 2 +- dummy-data/kafkaMessages/KafkaMessages.json | 24 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/dummy-data/ManageTestData.apex b/dummy-data/ManageTestData.apex index 4df91664..0e93cf7f 100644 --- a/dummy-data/ManageTestData.apex +++ b/dummy-data/ManageTestData.apex @@ -1,2 +1,2 @@ //Start executing AsyncRequests => Trigger handle the KafkaMessages -Database.executeBatch(new AsyncRequestBatchable(),50); \ No newline at end of file +Database.executeBatch(new AsyncRequestBatchable(),50); diff --git a/dummy-data/kafkaMessages/KafkaMessages.json b/dummy-data/kafkaMessages/KafkaMessages.json index 248c9d6a..077fe011 100644 --- a/dummy-data/kafkaMessages/KafkaMessages.json +++ b/dummy-data/kafkaMessages/KafkaMessages.json @@ -7,8 +7,28 @@ }, "CRM_Status__c": "Pending", "CRM_Topic__c": "teamnks.nks-sf-pdl-v3", - "CRM_Key__c": "eyJha3RvZXJfaWQiOiIyNDAwMDAwMDAwMDAwIiwidG9tYnN0b25lIjpmYWxzZX0=", - "CRM_Value__c": "eyJpZGVudGVyIjpbeyJpZGVudCI6IjIyMjU1NTAwMDAwIiwiaGlzdG9yaXNrIjp0cnVlLCJncnVwcGUiOiJOUElEIiwibWV0YWRhdGEiOm51bGwsImZvbGtlcmVnaXN0ZXJtZXRhZGF0YSI6bnVsbH0seyJpZGVudCI6IjQwMDAwMDAwMDAwIiwiaGlzdG9yaXNrIjp0cnVlLCJncnVwcGUiOiJGT0xLRVJFR0lTVEVSSURFTlQiLCJtZXRhZGF0YSI6bnVsbCwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjpudWxsfSx7ImlkZW50IjoiMDcwMDAwMDAwMDAiLCJoaXN0b3Jpc2siOmZhbHNlLCJncnVwcGUiOiJGT0xLRVJFR0lTVEVSSURFTlQiLCJtZXRhZGF0YSI6bnVsbCwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjpudWxsfSx7ImlkZW50IjoiMjQwMDAwMDAwMDAwMCIsImhpc3RvcmlzayI6ZmFsc2UsImdydXBwZSI6IkFLVE9SSUQiLCJtZXRhZGF0YSI6bnVsbCwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjpudWxsfV0sImZvbGtlcmVnaXN0ZXJpZGVudGlmaWthdG9yIjpbeyJpZGVudGlmaWthc2pvbnNudW1tZXIiOiI0MDAwMDAwMDAwMCIsInR5cGUiOiJETlIiLCJzdGF0dXMiOiJPUFBIT0VSVCIsIm1ldGFkYXRhIjp7Im9wcGx5c25pbmdzSWQiOiJhYTAwYWEwYS0wMDAwLTBhYWEtMDBhYS1hYTAwYWFhMGFhMDAiLCJtYXN0ZXIiOiJGUkVHIiwiaGlzdG9yaXNrIjp0cnVlLCJlbmRyaW5nZXIiOlt7InR5cGUiOiJPUFBSRVRUIiwicmVnaXN0cmVydCI6IjIwMjEtMDEtMDFUMDg6MDA6MDAuMDAwIiwicmVnaXN0cmVydEF2IjoiRm9sa2VyZWdpc3RlcmV0Iiwic3lzdGVta2lsZGUiOiJGUkVHIiwia2lsZGUiOiJ1dGxlbmRpbmdzZGlyZWt0b3JhdGV0In0seyJ0eXBlIjoiS09SUklHRVIiLCJyZWdpc3RyZXJ0IjoiMjAyMS0wMS0wMVQwODowMDowMC4wMDAiLCJyZWdpc3RyZXJ0QXYiOiJGb2xrZXJlZ2lzdGVyZXQiLCJzeXN0ZW1raWxkZSI6IkZSRUciLCJraWxkZSI6InV0bGVuZGluZ3NkaXJla3RvcmF0ZXQifV19LCJmb2xrZXJlZ2lzdGVybWV0YWRhdGEiOnsiYWpvdXJob2xkc3RpZHNwdW5rdCI6IjIwMjEtMDEtMDFUMDg6MDA6MDAuMDAwIiwiZ3lsZGlnaGV0c3RpZHNwdW5rdCI6IjIwMjEtMDEtMDFUMDg6MDA6MDAuMDAwIiwib3BwaG9lcnN0aWRzcHVua3QiOm51bGwsImtpbGRlIjoidXRsZW5kaW5nc2RpcmVrdG9yYXRldCIsImFhcnNhayI6IklubmZseXR0aW5nIn19LHsiaWRlbnRpZmlrYXNqb25zbnVtbWVyIjoiMDcwMDAwMDAwMDAiLCJ0eXBlIjoiRk5SIiwic3RhdHVzIjoiSV9CUlVLIiwibWV0YWRhdGEiOnsib3BwbHlzbmluZ3NJZCI6IjBhMDAwMDAwLTAwMDAtMDBhMC0wYWEwLTAwMDBhYWEwYTBhMCIsIm1hc3RlciI6IkZSRUciLCJoaXN0b3Jpc2siOmZhbHNlLCJlbmRyaW5nZXIiOlt7InR5cGUiOiJPUFBSRVRUIiwicmVnaXN0cmVydCI6IjIwMjEtMDEtMDFUMDg6MDA6MDAuMDAwIiwicmVnaXN0cmVydEF2IjoiRm9sa2VyZWdpc3RlcmV0Iiwic3lzdGVta2lsZGUiOiJGUkVHIiwia2lsZGUiOiJ1dGxlbmRpbmdzZGlyZWt0b3JhdGV0In1dfSwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjp7ImFqb3VyaG9sZHN0aWRzcHVua3QiOiIyMDIxLTAxLTAxVDA4OjAwOjAwLjAwMCIsImd5bGRpZ2hldHN0aWRzcHVua3QiOiIyMDIxLTAxLTAxVDA4OjAwOjAwLjAwMCIsIm9wcGhvZXJzdGlkc3B1bmt0IjpudWxsLCJraWxkZSI6InV0bGVuZGluZ3NkaXJla3RvcmF0ZXQiLCJhYXJzYWsiOiJJbm5mbHl0dGluZyJ9fV0sImFrdG9lcklkIjoiMjQwMDAwMDAwMDAwMCIsImZvbGtlcmVnaXN0ZXJJZCI6WyIwNzAwMDAwMDAwMCJdLCJuYXZuIjpbeyJmb3JuYXZuIjoiVEVTVCIsIm1lbGxvbW5hdm4iOm51bGwsImV0dGVybmF2biI6IlRFU1RFU0VOIn1dLCJmb3JlbGRlckJhcm5SZWxhc2pvbmVyIjpbeyJyZWxhdGVydFBlcnNvbnNJZGVudCI6IjQwMDAwMDAwMDAwIiwicmVsYXRlcnRQZXJzb25zUm9sbGUiOiJNT1IiLCJtaW5Sb2xsZUZvclBlcnNvbiI6IkJBUk4ifSx7InJlbGF0ZXJ0UGVyc29uc0lkZW50IjoiMDYwMDAwMDAwMDAiLCJyZWxhdGVydFBlcnNvbnNSb2xsZSI6IkZBUiIsIm1pblJvbGxlRm9yUGVyc29uIjoiQkFSTiJ9XSwiZm9sa2VyZWdpc3RlcnBlcnNvbnN0YXR1cyI6WyJib3NhdHQiXSwiaW5uZmx5dHRpbmdUaWxOb3JnZSI6W3siZnJhZmx5dHRpbmdzbGFuZCI6IlVHQSIsImZyYWZseXR0aW5nc3N0ZWRJVXRsYW5kZXQiOm51bGx9XSwiYWRyZXNzZWJlc2t5dHRlbHNlIjpbXSwic2lra2VyaGV0c3RpbHRhayI6W10sImJvc3RlZHNhZHJlc3NlIjp7InZlZ2FkcmVzc2UiOlt7ImtvbW11bmVudW1tZXIiOiIwMzAxIiwiYWRyZXNzZW5hdm4iOiJTbG90dHNwbGFzc2VuIiwiaHVzbnVtbWVyIjoiMSIsImh1c2Jva3N0YXYiOm51bGwsInBvc3RudW1tZXIiOiIwMDEwIiwiYnlkZWxzbnVtbWVyIjoiMDMwMTA0Iiwia29vcmRpbmF0ZXIiOiIxMjM0LjAsMTIzNC4wLDAuMCJ9XSwibWF0cmlra2VsYWRyZXNzZSI6W10sInV0ZW5sYW5kc2tBZHJlc3NlIjpbXSwidWtqZW50Qm9zdGVkIjpbXX0sIm9wcGhvbGRzYWRyZXNzZSI6eyJ2ZWdhZHJlc3NlIjpbXSwibWF0cmlra2VsYWRyZXNzZSI6W10sInV0ZW5sYW5kc2tBZHJlc3NlIjpbXSwidWtqZW50Qm9zdGVkIjpbXX0sInN0YXRzYm9yZ2Vyc2thcCI6WyJOT1IiXSwic2l2aWxzdGFuZCI6W3sidHlwZSI6IlVPUFBHSVRUIiwiZ3lsZGlnRnJhT2dNZWQiOiIyMDIxLTAxLTAxIiwicmVsYXRlcnRWZWRTaXZpbHN0YW5kIjpudWxsfV0sImtvbW11bmVudW1tZXJGcmFHdCI6IjAzMDEiLCJrb21tdW5lbnVtbWVyRnJhQWRyZXNzZSI6IjAzMDEiLCJieWRlbHNudW1tZXJGcmFHdCI6IjAzMDEwNCIsImJ5ZGVsc251bW1lckZyYUFkcmVzc2UiOiIwMzAxMDQiLCJram9lbm4iOlsiTUFOTiJdLCJkb2Vkc2ZhbGwiOltdLCJ0ZWxlZm9ubnVtbWVyIjpbXSwidXRmbHl0dGluZ0ZyYU5vcmdlIjpbXSwidGFsZXNzcHJhYWt0b2xrIjpbXSwiZnVsbG1ha3QiOltdLCJ2ZXJnZW1hYWxFbGxlckZyZW10aWRzZnVsbG1ha3QiOltdLCJmb2Vkc2Vsc2RhdG8iOlsiMjAwMC0wMS0wMSJdfQ" + "CRM_Key__c": "eyJha3RvZXJfaWQiOiIxMDk5NTExNjI3Nzc2IiwidG9tYnN0b25lIjpmYWxzZX0K", + "CRM_Value__c": "eyJpZGVudGVyIjpbeyJpZGVudCI6IjY4NzE5NDc2NzM2IiwiaGlzdG9yaXNrIjp0cnVlLCJncnVwcGUiOiJOUElEIiwibWV0YWRhdGEiOm51bGwsImZvbGtlcmVnaXN0ZXJtZXRhZGF0YSI6bnVsbH0seyJpZGVudCI6IjE3MTc5ODY5MTg0IiwiaGlzdG9yaXNrIjp0cnVlLCJncnVwcGUiOiJGT0xLRVJFR0lTVEVSSURFTlQiLCJtZXRhZGF0YSI6bnVsbCwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjpudWxsfSx7ImlkZW50IjoiMzQzNTk3MzgzNjgiLCJoaXN0b3Jpc2siOmZhbHNlLCJncnVwcGUiOiJGT0xLRVJFR0lTVEVSSURFTlQiLCJtZXRhZGF0YSI6bnVsbCwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjpudWxsfSx7ImlkZW50IjoiMTA5OTUxMTYyNzc3NiIsImhpc3RvcmlzayI6ZmFsc2UsImdydXBwZSI6IkFLVE9SSUQiLCJtZXRhZGF0YSI6bnVsbCwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjpudWxsfV0sImZvbGtlcmVnaXN0ZXJpZGVudGlmaWthdG9yIjpbeyJpZGVudGlmaWthc2pvbnNudW1tZXIiOiIxNzE3OTg2OTE4NCIsInR5cGUiOiJETlIiLCJzdGF0dXMiOiJPUFBIT0VSVCIsIm1ldGFkYXRhIjp7Im9wcGx5c25pbmdzSWQiOiJlYTc5YTc3YS1hYjA2LTExZWUtOTQ5Zi1iZjQ1NWUyOTMzNTMiLCJtYXN0ZXIiOiJGUkVHIiwiaGlzdG9yaXNrIjp0cnVlLCJlbmRyaW5nZXIiOlt7InR5cGUiOiJPUFBSRVRUIiwicmVnaXN0cmVydCI6IjIwMjEtMDEtMDFUMDg6MDA6MDAuMDAwIiwicmVnaXN0cmVydEF2IjoiRm9sa2VyZWdpc3RlcmV0Iiwic3lzdGVta2lsZGUiOiJGUkVHIiwia2lsZGUiOiJ1dGxlbmRpbmdzZGlyZWt0b3JhdGV0In0seyJ0eXBlIjoiS09SUklHRVIiLCJyZWdpc3RyZXJ0IjoiMjAyMS0wMS0wMVQwODowMDowMC4wMDAiLCJyZWdpc3RyZXJ0QXYiOiJGb2xrZXJlZ2lzdGVyZXQiLCJzeXN0ZW1raWxkZSI6IkZSRUciLCJraWxkZSI6InV0bGVuZGluZ3NkaXJla3RvcmF0ZXQifV19LCJmb2xrZXJlZ2lzdGVybWV0YWRhdGEiOnsiYWpvdXJob2xkc3RpZHNwdW5rdCI6IjIwMjEtMDEtMDFUMDg6MDA6MDAuMDAwIiwiZ3lsZGlnaGV0c3RpZHNwdW5rdCI6IjIwMjEtMDEtMDFUMDg6MDA6MDAuMDAwIiwib3BwaG9lcnN0aWRzcHVua3QiOm51bGwsImtpbGRlIjoidXRsZW5kaW5nc2RpcmVrdG9yYXRldCIsImFhcnNhayI6IklubmZseXR0aW5nIn19LHsiaWRlbnRpZmlrYXNqb25zbnVtbWVyIjoiMzQzNTk3MzgzNjgiLCJ0eXBlIjoiRk5SIiwic3RhdHVzIjoiSV9CUlVLIiwibWV0YWRhdGEiOnsib3BwbHlzbmluZ3NJZCI6ImQwOGYyZjYwLWFiMDYtMTFlZS1iZjg3LTYzYWFlYmY0ZTVjZiIsIm1hc3RlciI6IkZSRUciLCJoaXN0b3Jpc2siOmZhbHNlLCJlbmRyaW5nZXIiOlt7InR5cGUiOiJPUFBSRVRUIiwicmVnaXN0cmVydCI6IjIwMjEtMDEtMDFUMDg6MDA6MDAuMDAwIiwicmVnaXN0cmVydEF2IjoiRm9sa2VyZWdpc3RlcmV0Iiwic3lzdGVta2lsZGUiOiJGUkVHIiwia2lsZGUiOiJ1dGxlbmRpbmdzZGlyZWt0b3JhdGV0In1dfSwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjp7ImFqb3VyaG9sZHN0aWRzcHVua3QiOiIyMDIxLTAxLTAxVDA4OjAwOjAwLjAwMCIsImd5bGRpZ2hldHN0aWRzcHVua3QiOiIyMDIxLTAxLTAxVDA4OjAwOjAwLjAwMCIsIm9wcGhvZXJzdGlkc3B1bmt0IjpudWxsLCJraWxkZSI6InV0bGVuZGluZ3NkaXJla3RvcmF0ZXQiLCJhYXJzYWsiOiJJbm5mbHl0dGluZyJ9fV0sImFrdG9lcklkIjoiMTA5OTUxMTYyNzc3NiIsImZvbGtlcmVnaXN0ZXJJZCI6WyIzNDM1OTczODM2OCJdLCJuYXZuIjpbeyJmb3JuYXZuIjoiVEVTVCIsIm1lbGxvbW5hdm4iOm51bGwsImV0dGVybmF2biI6IlRFU1RFU0VOIn1dLCJmb3JlbGRlckJhcm5SZWxhc2pvbmVyIjpbeyJyZWxhdGVydFBlcnNvbnNJZGVudCI6IjE3MTc5ODY5MTg0IiwicmVsYXRlcnRQZXJzb25zUm9sbGUiOiJNT1IiLCJtaW5Sb2xsZUZvclBlcnNvbiI6IkJBUk4ifSx7InJlbGF0ZXJ0UGVyc29uc0lkZW50IjoiMTA0NjAzNTMyMDMiLCJyZWxhdGVydFBlcnNvbnNSb2xsZSI6IkZBUiIsIm1pblJvbGxlRm9yUGVyc29uIjoiQkFSTiJ9XSwiZm9sa2VyZWdpc3RlcnBlcnNvbnN0YXR1cyI6WyJib3NhdHQiXSwiaW5uZmx5dHRpbmdUaWxOb3JnZSI6W3siZnJhZmx5dHRpbmdzbGFuZCI6IlVHQSIsImZyYWZseXR0aW5nc3N0ZWRJVXRsYW5kZXQiOm51bGx9XSwiYWRyZXNzZWJlc2t5dHRlbHNlIjpbXSwic2lra2VyaGV0c3RpbHRhayI6W10sImJvc3RlZHNhZHJlc3NlIjp7InZlZ2FkcmVzc2UiOlt7ImtvbW11bmVudW1tZXIiOiIwMzAxIiwiYWRyZXNzZW5hdm4iOiJTbG90dHNwbGFzc2VuIiwiaHVzbnVtbWVyIjoiMSIsImh1c2Jva3N0YXYiOm51bGwsInBvc3RudW1tZXIiOiIwMDEwIiwiYnlkZWxzbnVtbWVyIjoiMDMwMTA0Iiwia29vcmRpbmF0ZXIiOiIxMjM0LjAsMTIzNC4wLDAuMCJ9XSwibWF0cmlra2VsYWRyZXNzZSI6W10sInV0ZW5sYW5kc2tBZHJlc3NlIjpbXSwidWtqZW50Qm9zdGVkIjpbXX0sIm9wcGhvbGRzYWRyZXNzZSI6eyJ2ZWdhZHJlc3NlIjpbXSwibWF0cmlra2VsYWRyZXNzZSI6W10sInV0ZW5sYW5kc2tBZHJlc3NlIjpbXSwidWtqZW50Qm9zdGVkIjpbXX0sInN0YXRzYm9yZ2Vyc2thcCI6WyJOT1IiXSwic2l2aWxzdGFuZCI6W3sidHlwZSI6IlVPUFBHSVRUIiwiZ3lsZGlnRnJhT2dNZWQiOiIyMDIxLTAxLTAxIiwicmVsYXRlcnRWZWRTaXZpbHN0YW5kIjpudWxsfV0sImtvbW11bmVudW1tZXJGcmFHdCI6IjAzMDEiLCJrb21tdW5lbnVtbWVyRnJhQWRyZXNzZSI6IjAzMDEiLCJieWRlbHNudW1tZXJGcmFHdCI6IjAzMDEwNCIsImJ5ZGVsc251bW1lckZyYUFkcmVzc2UiOiIwMzAxMDQiLCJram9lbm4iOlsiTUFOTiJdLCJkb2Vkc2ZhbGwiOltdLCJ0ZWxlZm9ubnVtbWVyIjpbXSwidXRmbHl0dGluZ0ZyYU5vcmdlIjpbXSwidGFsZXNzcHJhYWt0b2xrIjpbXSwiZnVsbG1ha3QiOltdLCJ2ZXJnZW1hYWxFbGxlckZyZW10aWRzZnVsbG1ha3QiOltdLCJmb2Vkc2Vsc2RhdG8iOlsiMjAwMC0wMS0wMSJdfQo=" + }, + { + "attributes": { + "type": "KafkaMessage__c", + "referenceId": "KafkaMessage__cRef2" + }, + "CRM_Status__c": "Pending", + "CRM_Topic__c": "pdl.pdl-persondokument-tagged-v1", + "CRM_Key__c": "2691212240800", + "CRM_Value__c": "eyJoZW50UGVyc29uIjp7ImFkcmVzc2ViZXNreXR0ZWxzZSI6W10sImJvc3RlZHNhZHJlc3NlIjpbeyJhbmdpdHRGbHl0dGVkYXRvIjoiMTk3Mi0wOS0yNiIsImd5bGRpZ0ZyYU9nTWVkIjoiMTk3Mi0wOS0yNlQwMDowMDowMCIsImd5bGRpZ1RpbE9nTWVkIjpudWxsLCJjb0FkcmVzc2VuYXZuIjpudWxsLCJ2ZWdhZHJlc3NlIjp7Im1hdHJpa2tlbElkIjozMzA0NjI4OTAsImh1c251bW1lciI6IjU0IiwiaHVzYm9rc3RhdiI6bnVsbCwiYnJ1a3NlbmhldHNudW1tZXIiOm51bGwsImFkcmVzc2VuYXZuIjoiVHJvbcO4eSBraXJrZXZlaSIsImtvbW11bmVudW1tZXIiOiI0MjAzIiwidGlsbGVnZ3NuYXZuIjpudWxsLCJwb3N0bnVtbWVyIjoiNDgxOCIsImJ5ZGVsc251bW1lciI6bnVsbCwia29vcmRpbmF0ZXIiOnsieCI6NDg5NjM5LjMsInkiOjY0Nzg4OTguOCwieiI6bnVsbH19LCJtYXRyaWtrZWxhZHJlc3NlIjpudWxsLCJ1a2plbnRCb3N0ZWQiOm51bGwsInV0ZW5sYW5kc2tBZHJlc3NlIjpudWxsLCJmb2xrZXJlZ2lzdGVybWV0YWRhdGEiOnsiYWpvdXJob2xkc3RpZHNwdW5rdCI6IjIwMjItMDEtMTRUMTU6NDE6MzkuODMiLCJneWxkaWdoZXRzdGlkc3B1bmt0IjoiMTk3Mi0wOS0yNlQwMDowMDowMCIsIm9wcGhvZXJzdGlkc3B1bmt0IjpudWxsLCJraWxkZSI6IkRvbGx5IiwiYWFyc2FrIjpudWxsLCJzZWt2ZW5zIjpudWxsfSwibWV0YWRhdGEiOnsib3BwbHlzbmluZ3NJZCI6IjU4MmQzMmE3LWY5MjMtNDY3YS05Y2Q2LTE3OTc2ZjY3MjdkMiIsIm1hc3RlciI6IkZSRUciLCJlbmRyaW5nZXIiOlt7InR5cGUiOiJPUFBSRVRUIiwicmVnaXN0cmVydCI6IjIwMjItMDEtMTRUMTU6NDE6MzkuODMiLCJyZWdpc3RyZXJ0QXYiOiJGb2xrZXJlZ2lzdGVyZXQiLCJzeXN0ZW1raWxkZSI6IkZSRUciLCJraWxkZSI6IkRvbGx5In1dLCJoaXN0b3Jpc2siOmZhbHNlfX1dLCJkb2Vkc2ZhbGwiOltdLCJmb2Vkc2VsIjpbeyJmb2Vkc2Vsc2FhciI6MTk3MiwiZm9lZHNlbHNkYXRvIjoiMTk3Mi0wOS0yNiIsImZvZWRlbGFuZCI6IklNTiIsImZvZWRlc3RlZCI6IkbDuGRlc3RlZCBpL3DDpSBJU0xFIE9GIE1BTiIsImZvZWRla29tbXVuZSI6bnVsbCwibWV0YWRhdGEiOnsib3BwbHlzbmluZ3NJZCI6ImI0M2QzNTFhLTlkMzQtNDAyNC04NDVmLThhZTE4ZTRmNThmZSIsIm1hc3RlciI6IkZSRUciLCJlbmRyaW5nZXIiOlt7InR5cGUiOiJPUFBSRVRUIiwicmVnaXN0cmVydCI6IjIwMjItMDEtMTRUMTU6NDE6MzguNTc0IiwicmVnaXN0cmVydEF2IjoiRm9sa2VyZWdpc3RlcmV0Iiwic3lzdGVta2lsZGUiOiJGUkVHIiwia2lsZGUiOiJEb2xseSJ9XSwiaGlzdG9yaXNrIjpmYWxzZX0sImZvbGtlcmVnaXN0ZXJtZXRhZGF0YSI6eyJham91cmhvbGRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTozOC41NzQiLCJneWxkaWdoZXRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTozOC41NzQiLCJvcHBob2Vyc3RpZHNwdW5rdCI6bnVsbCwia2lsZGUiOiJEb2xseSIsImFhcnNhayI6bnVsbCwic2VrdmVucyI6bnVsbH19XSwiZm9sa2VyZWdpc3RlcmlkZW50aWZpa2F0b3IiOlt7ImlkZW50aWZpa2Fzam9uc251bW1lciI6IjI2MDk3MjA5MTk2IiwidHlwZSI6IkZOUiIsInN0YXR1cyI6IklfQlJVSyIsImZvbGtlcmVnaXN0ZXJtZXRhZGF0YSI6eyJham91cmhvbGRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTozOC4wNzIiLCJneWxkaWdoZXRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTozOC4wNzIiLCJvcHBob2Vyc3RpZHNwdW5rdCI6bnVsbCwia2lsZGUiOiJzcnZkb2xseSIsImFhcnNhayI6bnVsbCwic2VrdmVucyI6bnVsbH0sIm1ldGFkYXRhIjp7Im9wcGx5c25pbmdzSWQiOiJhNDRiYjY2ZC0zNGUyLTQ0OWItOTJlNi05MGUyNGJkYjU4MjYiLCJtYXN0ZXIiOiJGUkVHIiwiZW5kcmluZ2VyIjpbeyJ0eXBlIjoiT1BQUkVUVCIsInJlZ2lzdHJlcnQiOiIyMDIyLTAxLTE0VDE1OjQxOjM4LjE5NiIsInJlZ2lzdHJlcnRBdiI6IkZvbGtlcmVnaXN0ZXJldCIsInN5c3RlbWtpbGRlIjoiRlJFRyIsImtpbGRlIjoic3J2ZG9sbHkifV0sImhpc3RvcmlzayI6ZmFsc2V9fV0sImZvbGtlcmVnaXN0ZXJwZXJzb25zdGF0dXMiOlt7InN0YXR1cyI6ImJvc2F0dCIsImZvcmVua2xldFN0YXR1cyI6ImJvc2F0dEV0dGVyRm9sa2VyZWdpc3RlcmxvdmVuIiwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjp7ImFqb3VyaG9sZHN0aWRzcHVua3QiOiIyMDIyLTAxLTE0VDE1OjQxOjQwLjc0MSIsImd5bGRpZ2hldHN0aWRzcHVua3QiOiIyMDIyLTAxLTE0VDE1OjQxOjQwLjc0MSIsIm9wcGhvZXJzdGlkc3B1bmt0IjpudWxsLCJraWxkZSI6IkRvbGx5IiwiYWFyc2FrIjpudWxsLCJzZWt2ZW5zIjpudWxsfSwibWV0YWRhdGEiOnsib3BwbHlzbmluZ3NJZCI6Ijg4ZWIxMTFhLWFiYzQtNDkwNi1iMWVmLWY1Njg5MjE0YzMxZCIsIm1hc3RlciI6IkZSRUciLCJlbmRyaW5nZXIiOlt7InR5cGUiOiJPUFBSRVRUIiwicmVnaXN0cmVydCI6IjIwMjItMDEtMTRUMTU6NDE6NDAuNzQxIiwicmVnaXN0cmVydEF2IjoiRm9sa2VyZWdpc3RlcmV0Iiwic3lzdGVta2lsZGUiOiJGUkVHIiwia2lsZGUiOiJEb2xseSJ9XSwiaGlzdG9yaXNrIjpmYWxzZX19XSwiZm9yZWxkZXJCYXJuUmVsYXNqb24iOltdLCJmdWxsbWFrdCI6W10sImtqb2VubiI6W3sia2pvZW5uIjoiTUFOTiIsImZvbGtlcmVnaXN0ZXJtZXRhZGF0YSI6eyJham91cmhvbGRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTozOS40NyIsImd5bGRpZ2hldHN0aWRzcHVua3QiOiIyMDIyLTAxLTE0VDE1OjQxOjM5LjQ3Iiwib3BwaG9lcnN0aWRzcHVua3QiOm51bGwsImtpbGRlIjoiRG9sbHkiLCJhYXJzYWsiOm51bGwsInNla3ZlbnMiOm51bGx9LCJtZXRhZGF0YSI6eyJvcHBseXNuaW5nc0lkIjoiZWVmNzkxZGMtMmE3NC00OWQ2LWFjNTEtOWE1MzQ2YjE1ZDQ0IiwibWFzdGVyIjoiRlJFRyIsImVuZHJpbmdlciI6W3sidHlwZSI6Ik9QUFJFVFQiLCJyZWdpc3RyZXJ0IjoiMjAyMi0wMS0xNFQxNTo0MTozOS40NyIsInJlZ2lzdHJlcnRBdiI6IkZvbGtlcmVnaXN0ZXJldCIsInN5c3RlbWtpbGRlIjoiRlJFRyIsImtpbGRlIjoiRG9sbHkifV0sImhpc3RvcmlzayI6ZmFsc2V9fV0sIm5hdm4iOlt7ImZvcm5hdm4iOiJUUkVJRyIsIm1lbGxvbW5hdm4iOm51bGwsImV0dGVybmF2biI6IkhBVFQiLCJmb3Jrb3J0ZXROYXZuIjpudWxsLCJvcmlnaW5hbHROYXZuIjpudWxsLCJneWxkaWdGcmFPZ01lZCI6IjIwMjItMDEtMTQiLCJmb2xrZXJlZ2lzdGVybWV0YWRhdGEiOnsiYWpvdXJob2xkc3RpZHNwdW5rdCI6IjIwMjItMDEtMTRUMTU6NDE6MzkuMDQiLCJneWxkaWdoZXRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTozOS4wNCIsIm9wcGhvZXJzdGlkc3B1bmt0IjpudWxsLCJraWxkZSI6IkRvbGx5IiwiYWFyc2FrIjpudWxsLCJzZWt2ZW5zIjpudWxsfSwibWV0YWRhdGEiOnsib3BwbHlzbmluZ3NJZCI6IjI2ODAxMGE1LTVmODgtNGE4NS04MDMyLTMxMjYzZGQyODQxMSIsIm1hc3RlciI6IkZSRUciLCJlbmRyaW5nZXIiOlt7InR5cGUiOiJPUFBSRVRUIiwicmVnaXN0cmVydCI6IjIwMjItMDEtMTRUMTU6NDE6MzkuMDQiLCJyZWdpc3RyZXJ0QXYiOiJGb2xrZXJlZ2lzdGVyZXQiLCJzeXN0ZW1raWxkZSI6IkZSRUciLCJraWxkZSI6IkRvbGx5In1dLCJoaXN0b3Jpc2siOmZhbHNlfX1dLCJvcHBob2xkc2FkcmVzc2UiOltdLCJzaWtrZXJoZXRzdGlsdGFrIjpbXSwic2l2aWxzdGFuZCI6W3sidHlwZSI6IlVPUFBHSVRUIiwiZ3lsZGlnRnJhT2dNZWQiOm51bGwsInJlbGF0ZXJ0VmVkU2l2aWxzdGFuZCI6bnVsbCwiYmVrcmVmdGVsc2VzZGF0byI6bnVsbCwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjp7ImFqb3VyaG9sZHN0aWRzcHVua3QiOiIyMDIyLTAxLTE0VDE1OjQxOjQxLjU4OSIsImd5bGRpZ2hldHN0aWRzcHVua3QiOiIyMDIyLTAxLTE0VDE1OjQxOjQxLjU4OSIsIm9wcGhvZXJzdGlkc3B1bmt0IjpudWxsLCJraWxkZSI6IkRvbGx5IiwiYWFyc2FrIjpudWxsLCJzZWt2ZW5zIjpudWxsfSwibWV0YWRhdGEiOnsib3BwbHlzbmluZ3NJZCI6IjdlYTE5NGE4LWM1YjktNDEzMC05MjAxLWFjOWUzYjJkZmQ3NiIsIm1hc3RlciI6IkZSRUciLCJlbmRyaW5nZXIiOlt7InR5cGUiOiJPUFBSRVRUIiwicmVnaXN0cmVydCI6IjIwMjItMDEtMTRUMTU6NDE6NDEuNTg5IiwicmVnaXN0cmVydEF2IjoiRm9sa2VyZWdpc3RlcmV0Iiwic3lzdGVta2lsZGUiOiJGUkVHIiwia2lsZGUiOiJEb2xseSJ9XSwiaGlzdG9yaXNrIjpmYWxzZX19XSwic3RhdHNib3JnZXJza2FwIjpbeyJsYW5kIjoiTk9SIiwiYmVrcmVmdGVsc2VzZGF0byI6bnVsbCwiZ3lsZGlnRnJhT2dNZWQiOiIxOTcyLTA5LTI2IiwiZ3lsZGlnVGlsT2dNZWQiOm51bGwsImZvbGtlcmVnaXN0ZXJtZXRhZGF0YSI6eyJham91cmhvbGRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTo0MS4xODIiLCJneWxkaWdoZXRzdGlkc3B1bmt0IjoiMTk3Mi0wOS0yNlQwMDowMDowMCIsIm9wcGhvZXJzdGlkc3B1bmt0IjpudWxsLCJraWxkZSI6IkRvbGx5IiwiYWFyc2FrIjpudWxsLCJzZWt2ZW5zIjpudWxsfSwibWV0YWRhdGEiOnsib3BwbHlzbmluZ3NJZCI6IjNiOWQ2MTYxLWE3YzQtNDFmZi1hOGM4LTFlMTE5MmE3Y2RjZiIsIm1hc3RlciI6IkZSRUciLCJlbmRyaW5nZXIiOlt7InR5cGUiOiJPUFBSRVRUIiwicmVnaXN0cmVydCI6IjIwMjItMDEtMTRUMTU6NDE6NDEuMTgyIiwicmVnaXN0cmVydEF2IjoiRm9sa2VyZWdpc3RlcmV0Iiwic3lzdGVta2lsZGUiOiJGUkVHIiwia2lsZGUiOiJEb2xseSJ9XSwiaGlzdG9yaXNrIjpmYWxzZX19XSwidGlscmV0dGVsYWd0S29tbXVuaWthc2pvbiI6W10sInRlbGVmb25udW1tZXIiOltdLCJpbm5mbHl0dGluZ1RpbE5vcmdlIjpbeyJmcmFmbHl0dGluZ3NsYW5kIjoiSU1OIiwiZnJhZmx5dHRpbmdzc3RlZElVdGxhbmRldCI6bnVsbCwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjp7ImFqb3VyaG9sZHN0aWRzcHVua3QiOiIyMDIyLTAxLTE0VDE1OjQxOjQwLjIwNSIsImd5bGRpZ2hldHN0aWRzcHVua3QiOiIxOTcyLTA5LTI2VDAwOjAwOjAwIiwib3BwaG9lcnN0aWRzcHVua3QiOm51bGwsImtpbGRlIjoiRG9sbHkiLCJhYXJzYWsiOm51bGwsInNla3ZlbnMiOm51bGx9LCJtZXRhZGF0YSI6eyJvcHBseXNuaW5nc0lkIjoiNGZjZTE0ZDEtZTZkNy00OTQwLWFmY2ItNzIwZGU2YzVhYmVmIiwibWFzdGVyIjoiRlJFRyIsImVuZHJpbmdlciI6W3sidHlwZSI6Ik9QUFJFVFQiLCJyZWdpc3RyZXJ0IjoiMjAyMi0wMS0xNFQxNTo0MTo0MC4yMDUiLCJyZWdpc3RyZXJ0QXYiOiJGb2xrZXJlZ2lzdGVyZXQiLCJzeXN0ZW1raWxkZSI6IkZSRUciLCJraWxkZSI6IkRvbGx5In1dLCJoaXN0b3Jpc2siOmZhbHNlfX1dLCJ1dGZseXR0aW5nRnJhTm9yZ2UiOltdLCJ2ZXJnZW1hYWxFbGxlckZyZW10aWRzZnVsbG1ha3QiOltdfSwiaGVudElkZW50ZXIiOnsiaWRlbnRlciI6W3siaWRlbnQiOiIyNjA5NzIwOTE5NiIsImhpc3RvcmlzayI6ZmFsc2UsImdydXBwZSI6IkZPTEtFUkVHSVNURVJJREVOVCIsIm1ldGFkYXRhIjpudWxsLCJmb2xrZXJlZ2lzdGVybWV0YWRhdGEiOm51bGx9LHsiaWRlbnQiOiIyNjkxMjEyMjQwODAwIiwiaGlzdG9yaXNrIjpmYWxzZSwiZ3J1cHBlIjoiQUtUT1JJRCIsIm1ldGFkYXRhIjpudWxsLCJmb2xrZXJlZ2lzdGVybWV0YWRhdGEiOm51bGx9XX19Cg==" + }, + { + "attributes": { + "type": "KafkaMessage__c", + "referenceId": "KafkaMessage__cRef3" + }, + "CRM_Status__c": "Pending", + "CRM_Topic__c": "pdl.geografisktilknytning-v1", + "CRM_Key__c": "2584233575802", + "CRM_Value__c": "eyJpZGVudGVyIjpbIjI2OTEyMTIyNDA4MDAiLCIyNjA5NzIwOTE5NiJdLCJnZW9ncmFmaXNrVGlsa255dG5pbmciOnsiZ3RUeXBlIjoiS09NTVVORSIsImd0S29tbXVuZSI6IjQ2MTQiLCJndEJ5ZGVsIjpudWxsLCJndExhbmQiOm51bGwsInJlZ2VsIjoiMiJ9fQo=" } ] } From 38a80b2e78483e10cb88df502ab5a9dc9178976e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 10 Jan 2024 16:55:23 +0100 Subject: [PATCH 003/159] =?UTF-8?q?POC=20=E2=80=93=20create=20person=20fro?= =?UTF-8?q?m=20GeografiskTilknytning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../classes/PdlGeografiskTilknytning.cls | 7 + .../PdlGeografiskTilknytning.cls-meta.xml | 5 + .../pdl-handler/classes/KafkaPdlGtHandler.cls | 75 + .../classes/KafkaPdlGtHandler.cls-meta.xml | 5 + .../classes/KafkaPdlGtHandlerTest.cls | 35 + .../KafkaPdlGtHandlerTest.cls-meta.xml | 5 + .../classes/KafkaPdlPersondokumentHandler.cls | 879 ++++++++++ ...KafkaPdlPersondokumentHandler.cls-meta.xml | 5 + .../KafkaPdlPersondokumentHandlerTest.cls | 1511 +++++++++++++++++ ...aPdlPersondokumentHandlerTest.cls-meta.xml | 5 + .../pdl-handler/classes/KafkaPersonGt.cls | 11 + .../classes/KafkaPersonGt.cls-meta.xml | 5 + ...nding.PdlGeografiskTilknytning.md-meta.xml | 29 + 13 files changed, 2577 insertions(+) create mode 100644 force-app/pdl-apexTypes/classes/PdlGeografiskTilknytning.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlGeografiskTilknytning.cls-meta.xml create mode 100644 force-app/pdl-handler/classes/KafkaPdlGtHandler.cls create mode 100644 force-app/pdl-handler/classes/KafkaPdlGtHandler.cls-meta.xml create mode 100644 force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls create mode 100644 force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls-meta.xml create mode 100644 force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls create mode 100644 force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls-meta.xml create mode 100644 force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls create mode 100644 force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls-meta.xml create mode 100644 force-app/pdl-handler/classes/KafkaPersonGt.cls create mode 100644 force-app/pdl-handler/classes/KafkaPersonGt.cls-meta.xml create mode 100644 force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlGeografiskTilknytning.md-meta.xml diff --git a/force-app/pdl-apexTypes/classes/PdlGeografiskTilknytning.cls b/force-app/pdl-apexTypes/classes/PdlGeografiskTilknytning.cls new file mode 100644 index 00000000..4ff0a0b4 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlGeografiskTilknytning.cls @@ -0,0 +1,7 @@ +public with sharing class PdlGeografiskTilknytning { + public String gtType{get;} + public String gtKommune{get;} + public String gtBydel{get;} + public String gtLand{get;} + public String regel{get;} +} diff --git a/force-app/pdl-apexTypes/classes/PdlGeografiskTilknytning.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlGeografiskTilknytning.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlGeografiskTilknytning.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls new file mode 100644 index 00000000..ba5412e7 --- /dev/null +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -0,0 +1,75 @@ +/** + * all the gt-related fields factored out from the previous implementation, + * KafkaPDLHandler2 , + * since they now arrive in separate kafka messages. + */ +public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer { + + public class PdlGtException extends Exception { + } + + private void assignIdent(Person__c p, String s) { + if(s.length() == 13) { + p.INT_ActorId__c = s; + } else if(s.length() == 11) { + if(Integer.valueOf(s.left(1)) >= 4) { + p.INT_dnr__c = s; + } else { + p.INT_fnr__c = s; + } + p.Name = s; // flows to Account.INT_PersonIdent__c + } else { + throw new PdlGtException('Unrecognised ident.'); + } + } + + /** + * Transform and map fields from PDL data structure to Person__c SObject + * @param person New Person__c SObject record + * @param kafkaPerson deserialized object representing a person from PDL + * @return Person Account with initialized fields + */ + private Person__c personFromKafkaPerson(KafkaPersonGT kafkaPerson) { + Person__c person = new Person__c(); + for(String s : kafkaPerson.identer) { + assignIdent(person, s); + } + + // TODO obviously expand this + PdlGeografiskTilknytning gt = kafkaPerson.geografiskTilknytning; + person.INT_GTMunicipalityNumber__c = gt.gtKommune; + + // Ensure that a System User is set as Owner if even if message processing is manually retried by an administrator user + if (KafkaIntegrationCustomSetting.integrationUserId != null) { + person.OwnerId = KafkaIntegrationCustomSetting.integrationUserId; + } + return person; + } + + /** + * Orchestrate deserialization, transformation, and Person__c creation for each KafkaMessage + * @param message integration record inserted by the integration user + * @return Initialized Person Account ready for DML + */ + private Person__c createPersonRecord(KafkaMessage__c message) { + String decodedValue = KafkaMessageUtils.base64ULSafeDecode(message.CRM_Value__c).toString(); + KafkaPersonGT kafkaPerson = KafkaPersonGT.parse(decodedValue); + Person__c person = personFromKafkaPerson(kafkaPerson); + person.INT_LastUpdatedFromPDL__c = message.createdDate; + // ... + return person; + } + + public void processMessages(List messages) { + List persons = new List(); + for (KafkaMessage__c msg : messages) { + if (msg.CRM_Status__c == KafkaMessageService.STATUS_PENDING) { + Person__c p = createPersonRecord(msg); + persons.add(p); + msg.CRM_Status__c = KafkaMessageService.STATUS_PROCESSED; + } + } + List urList = Database.upsert(persons, Person__c.INT_ActorId__c, false); + // TODO check for errors, set status to error if so + } +} diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls-meta.xml b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls new file mode 100644 index 00000000..066315a3 --- /dev/null +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -0,0 +1,35 @@ +@IsTest +private with sharing class KafkaPdlGtHandlerTest { + + @isTest + static void testCreatePersonFromGt() { + List kafkaMessages = new List(); + kafkaMessages.add( + new KafkaMessage__c( + CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Key__c = '1017419408436', + //{ + // "identer": [ + // "1017419408436", + // "74194084361" + // ], + // "geografiskTilknytning": { + // "gtType": "KOMMUNE", + // "gtKommune": "1337", + // "gtBydel": null, + // "gtLand": null, + // "regel": "2" + // } + //} + CRM_Value__c = 'eyJpZGVudGVyIjpbIjEwMTc0MTk0MDg0MzYiLCI3NDE5NDA4NDM2MSJdLCJnZW9ncmFmaXNrVGlsa255dG5pbmciOnsiZ3RUeXBlIjoiS09NTVVORSIsImd0S29tbXVuZSI6IjEzMzciLCJndEJ5ZGVsIjpudWxsLCJndExhbmQiOm51bGwsInJlZ2VsIjoiMiJ9fQo=', + CRM_Status__c = KafkaMessageService.STATUS_PENDING + ) + ); + Test.startTest(); + KafkaPdlGtHandler handler = new KafkaPdlGtHandler(); + handler.processMessages(kafkaMessages); + List pl = [SELECT Id from Person__c where INT_ActorId__c = '1017419408436']; + Assert.areEqual(1, pl.size(), 'Expected one person inserted.'); + Test.stopTest(); + } +} diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls-meta.xml b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls new file mode 100644 index 00000000..f7ffaa25 --- /dev/null +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -0,0 +1,879 @@ +/** + * Yes, just a copy of KafkaPDLHandler2 for now. + */ +public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMessageConsumer { + @TestVisible + private static final String PDL_ERROR_STRING = ''; + + @TestVisible + private static final Map ADR_BESKYTTELSES_GRADERING = new Map{ + 'STRENGT_FORTROLIG' => 4, + 'STRENGT_FORTROLIG_UTLAND' => 3, + 'FORTROLIG' => 2, + 'UGRADERT' => 1 + }; + @TestVisible + private static final Map ISO_MAP = createIsoMap( + [ + SELECT Name, CRM_Code__c + FROM Common_Code__c + WHERE CRM_Active__c = TRUE AND CRM_Code_Set__c IN ('Landkoder', 'LandkoderISO2') + ] + ); + + private Set existingActors; + + private LoggerUtility logger; + + public void processMessages(List messages) { + logger = new LoggerUtility('PDL'); + Map personMap = new Map(); + existingActors = new Set(); + Map messageMap = new Map(); + + //If we have a message where the created date is older than last updated, set it to error so that we can investigate it. + //If we have a tombstone without a person in Salesforce, set it to processed. + checkLastUpdatedAndTombStones(messages); + + // Errors are caught and saved on each KafkaMessage record + for (KafkaMessage__c msg : messages) { + if (msg.CRM_Status__c == KafkaMessageService.STATUS_PENDING) { + try { + Person__c person = createPersonRecords(msg); + personMap.put(person.INT_ActorId__c, person); + messageMap.put(person.INT_ActorId__c, msg); + msg.CRM_Status__c = KafkaMessageService.STATUS_PROCESSED; + } catch (PdlIdentException e) { + String errorMsg = e.getTypeName() + ': ' + e.getMessage() + ' (' + e.getLineNumber() + ')'; + setMessageError(errorMsg, msg, KafkaMessageService.STATUS_ERROR); + logger.error( + 'Error creatign Person__c from PDL Kafka message. ' + + '\n ' + + e.getMessage() + + '\n Kafka key reference: ' + + msg.CRM_Key__c, + null, + CRM_ApplicationDomain.domain.NKS + ); + } catch (Exception e) { + String errorMsg = e.getTypeName() + ': ' + e.getMessage() + ' (' + e.getLineNumber() + ')'; + setMessageError(errorMsg, msg); + if (msg.CRM_Status__c == KafkaMessageService.STATUS_ERROR) { + logger.error( + 'Error creatign Person__c from PDL Kafka message. ' + + '\n Kafka key reference: ' + + msg.CRM_Key__c, + null, + CRM_ApplicationDomain.domain.NKS + ); + } else if (msg.CRM_Status__c == KafkaMessageService.STATUS_WARNING) { + logger.warning( + 'Warning creatign Person__c from PDL Kafka message. ' + + '\n Kafka key reference: ' + + msg.CRM_Key__c, + null, + CRM_ApplicationDomain.domain.NKS + ); + } + } + } + } + List personList = new List(); + List messageList = new List(); + for (String actorId : personMap.keySet()) { + personList.add(personMap.get(actorId)); + messageList.add(messageMap.get(actorId)); + } + // Errors from DML will set all messages to failed. + // try { + List urList = Database.upsert(personList, Person__c.INT_ActorId__c, false); + for (Integer i = 0; i < urList.size(); i++) { + if (false == urList[i].isSuccess()) { + String errorMsg = 'Upsert error:'; + for (Database.Error error : urList[i].getErrors()) { + errorMsg += ' * ' + error.getMessage(); + } + setMessageError(errorMsg, messageList[i]); + if (messageList[i].CRM_Status__c == KafkaMessageService.STATUS_ERROR) { + logger.error( + 'Error updating Person__c.' + + '\n Kafka key reference: ' + + messageList[i].CRM_Key__c, + null, + CRM_ApplicationDomain.domain.NKS + ); + } else if (messageList[i].CRM_Status__c == KafkaMessageService.STATUS_WARNING) { + logger.warning( + 'Warning updating Person__c.' + + '\n Kafka key reference: ' + + messageList[i].CRM_Key__c, + null, + CRM_ApplicationDomain.domain.NKS + ); + } + } + } + logger.publish(); + } + + /** + * Validates that the Kafka Message is not older than the last PDL Update on the Person + * If a new person is a tombstone, do not import it + * @param messages Set of Kafka Messages in scope + * @return Deduplicated set of Kafka Message + */ + @TestVisible + private void checkLastUpdatedAndTombStones(List messages) { + List idList = new List(); + List tombList = new List(); + Set tombSet = new Set(); + Set personTombSet = new Set(); + List personIdList = new List(); + List updatedList = new List(); + Map updatedMap = new Map(); + Set split = new Set(); + + for (KafkaMessage__c msg : messages) { + Key k = getKeyFromBase64(msg.CRM_Key__c); + //Lists of key values wich match order of kafka messages + idList.add(k.aktoer_id); + tombList.add(k.tombstone); + //A Set of idents with tombstones from kafka messages + if (k.tombstone == true) { + tombSet.add(k.aktoer_id); + } + } + for (Person__c p : [ + SELECT INT_ActorId__c, INT_LastUpdatedFromPDL__c, INT_IsHasTombstone__c + FROM Person__c + WHERE INT_ActorId__c IN :idList + ]) { + if (p.INT_IsHasTombstone__c) { + //A Set of idents wich already has tombstones + personTombSet.add(p.INT_ActorId__c); + } + //A List with ident for existing persons + personIdList.add(p.INT_ActorId__c); + //A List of Update Datetime values (same order as personIdList) + updatedList.add(p.INT_LastUpdatedFromPDL__c); + } + for (Integer i = 0; i < personIdList.size(); i++) { + System.debug('for: ' + personIdList[i]); + if (!personTombSet.contains(personIdList[i]) && !split.contains(personIdList[i])) { + if (!updatedMap.containsKey(personIdList[i])) { + //A Map with ident as a key and LastUpdate as a value for existing persons + updatedMap.put(personIdList[i], updatedList[i]); + } else { + //in case if there are several persons with same actorId making a list for it + split.add(personIdList[i]); + updatedMap.remove(personIdList[i]); + } + } + } + existingActors = updatedMap.keySet(); + + for (Integer i = 0; i < messages.size(); i++) { + if (split.contains(idList[i])) { + //when a few person records with same actor id exists + setMessageError( + 'There exists more than one records for Id.(split/merge)', + messages[i], + KafkaMessageService.STATUS_ERROR + ); + } else if (personTombSet.contains(idList[i])) { + //when person already exists and has tombstone + setMessageError('Trying update Tombstone.', messages[i], KafkaMessageService.STATUS_WARNING); + } else if (updatedMap.containsKey(idList[i]) && (messages[i].createdDate < updatedMap.get(idList[i]))) { + //when person exists and has more recent update + setMessageError( + 'Trying update a newer record. Skip update.', + messages[i], + KafkaMessageService.STATUS_WARNING + ); + } else if (!tombList[i] && tombSet.contains(idList[i])) { + //when there is update and tombstone messages for same person in the list + setMessageError( + 'There is a Tombstone message for person. Skip update.', + messages[i], + KafkaMessageService.STATUS_WARNING + ); + } else if (!updatedMap.containsKey(idList[i]) && tombList[i]) { + setMessageError( + 'Trying insert Tombstone. Skip insert.', + messages[i], + KafkaMessageService.STATUS_PROCESSED + ); + } + } + } + + private Map getPersonLastUpdatedMap(List actorIds) { + Map lastUpdatedMap = new Map(); + + for (Person__c p : [ + SELECT INT_ActorId__c, INT_LastUpdatedFromPDL__c + FROM Person__c + WHERE INT_ActorId__c IN :actorIds + ]) { + lastUpdatedMap.put(p.INT_ActorId__c, p.INT_LastUpdatedFromPDL__c); + } + + return lastUpdatedMap; + } + + /** + * Orchestrate deserialization, transformation, and Person__c creation for each KafkaMessage + * @param message integration record inserted by the integration user + * @return Initialized Person Account ready for DML + */ + private Person__c createPersonRecords(KafkaMessage__c message) { + Person__c person = new Person__c(); + person = setTombstoneFlag(person, message); + person.INT_LastUpdatedFromPDL__c = message.createdDate; + + //If tombstone and no payload, clear data for person except idents. + if (true == person.INT_IsHasTombstone__c && String.isBlank(message.CRM_Value__c)) { + emptyTombstonePerson(person); + return person; + } + + emptyPersonFieldValues(person); + + String decodedValue = KafkaMessageUtils.base64ULSafeDecode(message.CRM_Value__c).toString(); + KafkaPerson2 kafkaPerson = KafkaPerson2.parse(decodedValue); + + validateListSizes(kafkaPerson); + person = mapFieldValues(person, kafkaPerson); + + return person; + } + + /** + * Transform and map fields from PDL data structure to Person__c SObject + * @param person New Person__c SObject record + * @param kafkaPerson deserialized object representing a person from PDL + * @return Person Account with initialized fields + */ + private Person__c mapFieldValues(Person__c person, KafkaPerson2 kafkaPerson) { + if (kafkaPerson.identer != null && kafkaPerson.identer.isEmpty() == false) { + setIdents(kafkaPerson, person); + setName(kafkaPerson, person); + } else { + person.INT_ActorId__c = kafkaPerson.aktoerId; + if (kafkaPerson.folkeregisterId.size() > 0) { + person.Name = kafkaPerson.folkeregisterId[0]; + } + } + + if (kafkaPerson.foedselsdato.size() > 0) { + person.INT_DateOfBirth__c = kafkaPerson.foedselsdato[kafkaPerson.foedselsdato.size() - 1]; + } + // Navn + if (kafkaPerson.Navn.size() > 0) { + person.INT_FirstName__c = stringValidator(kafkaPerson.Navn[kafkaPerson.Navn.size() - 1].fornavn); + person.INT_MiddleName__c = stringValidator(kafkaPerson.Navn[kafkaPerson.Navn.size() - 1].mellomnavn); + person.INT_LastName__c = stringValidator(kafkaPerson.Navn[kafkaPerson.Navn.size() - 1].etternavn); + } + + // folkeregisterpersonstatus + if (kafkaPerson.folkeregisterpersonstatus.size() > 0) { + person.INT_LegalStatus__c = kafkaPerson.folkeregisterpersonstatus[0]; + } + + // InnflytningTilNorge + if (kafkaPerson.innflyttingTilNorge.size() > 0) { + person.INT_MovedFromCountry__c = getCountryIdFromIso( + kafkaPerson.innflyttingTilNorge[kafkaPerson.innflyttingTilNorge.size() - 1].fraflyttingsland + ); + person.INT_MovedFromPlace__c = kafkaPerson.innflyttingTilNorge[kafkaPerson.innflyttingTilNorge.size() - 1] + .fraflyttingsstedIUtlandet; + } + + // adressebeskyttelse + person.INT_Confidential__c = setClearanceLevel(kafkaPerson.adressebeskyttelse); + + // sikkerhetstiltak + person.INT_SecurityMeasures__c = JSON.serialize(kafkaPerson.sikkerhetstiltak); + + // adresse + setAddress(person, kafkaPerson); + + setMunicipalityAndGT(person, kafkaPerson); + + // statsborgerskap + person.INT_Citizenships__c = crateCitizenshipString(kafkaPerson.statsborgerskap); + + // sivilstand + if (kafkaPerson.sivilstand.size() > 0) { + person.INT_MaritalStatus__c = kafkaPerson.sivilstand[kafkaPerson.sivilstand.size() - 1].type.name(); + // person.INT_MaritalStatusDate__c = dateCreator( + // kafkaPerson.sivilstand[kafkaPerson.sivilstand.size() - 1].gyldigFraOgMed + // ); + person.INT_MaritalStatusDate__c = kafkaPerson.sivilstand[kafkaPerson.sivilstand.size() - 1].gyldigFraOgMed; + person.INT_MaritalRelation__c = kafkaPerson.sivilstand[kafkaPerson.sivilstand.size() - 1] + .relatertVedSivilstand; + } + + // kjoenn + if (kafkaPerson.kjoenn.size() > 0) { + person.INT_Sex__c = kafkaPerson.kjoenn[0]; + } + // doedsfall + if (kafkaPerson.doedsfall.size() > 0) { + person.INT_DateOfDeath__c = getDoedsfall(kafkaPerson.doedsfall); + person.INT_IsDeceased__c = true; //If we got any records return true even if we don't have a date. + } + + // telefonnummer + for (KafkaPerson2.telefonnummer tlf : kafkaPerson.telefonnummer) { + if (tlf.prioritet == '1') { + person.INT_Phone1__c = tlf.landskode + tlf.nummer; + } + if (tlf.prioritet == '2') { + person.INT_Phone2__c = tlf.landskode + tlf.nummer; + } + } + + // utflyttingFraNorge + if (kafkaPerson.utflyttingFraNorge.size() > 0) { + person.INT_MovedToCountry__c = getCountryIdFromIso( + kafkaPerson.utflyttingFraNorge[kafkaPerson.utflyttingFraNorge.size() - 1].tilflyttingsland + ); + person.INT_MovedToPlace__c = kafkaPerson.utflyttingFraNorge[kafkaPerson.utflyttingFraNorge.size() - 1] + .tilflyttingsstedIUtlandet; + } + + // talesspraaktolk + person.INT_SpokenLanguageIntepreter__c = safelyJoinMultiPicklistString(kafkaPerson.talesspraaktolk); + + // fullmakt + person.INT_PowerOfAttorney__c = (kafkaPerson.fullmakt == null || + kafkaPerson.fullmakt.size() == 0) + ? null + : JSON.serialize(kafkaPerson.fullmakt); + + // vergemaalEllerFremtidsfullmakt + person.INT_GuardianshipOrFuturePowerOfAttorney__c = (kafkaPerson.vergemaalEllerFremtidsfullmakt == null || + kafkaPerson.vergemaalEllerFremtidsfullmakt.size() == 0) + ? null + : JSON.serialize(kafkaPerson.vergemaalEllerFremtidsfullmakt); + + // Ensure that a System User is set as Owner if even if message processing is manually retried by an administrator user + if (KafkaIntegrationCustomSetting.integrationUserId != null) { + person.OwnerId = KafkaIntegrationCustomSetting.integrationUserId; + } + return person; + } + + private Person__c setTombstoneFlag(Person__c person, KafkaMessage__c message) { + String decodedValue = KafkaMessageUtils.base64ULSafeDecode(message.CRM_Key__c).toString(); + Key key = (Key) System.JSON.deserialize(decodedValue, Key.class); + person.INT_IsHasTombstone__c = key.tombstone; + person.INT_ActorId__c = key.aktoer_id; + return person; + } + + @TestVisible + private void setAddress(Person__c person, KafkaPerson2 kafkaPerson) { + if (ADR_BESKYTTELSES_GRADERING.get(person.INT_Confidential__c) <= 2) { + // bostedsadresser + // assumption: vegadresse has first pri, then ukjentbosted + if (kafkaPerson.bostedsadresse.vegadresse.size() > 0) { + person.INT_ResidentialAddress__c = addressCreator( + new List{ + kafkaPerson.bostedsadresse.vegadresse[0].adressenavn, + kafkaPerson.bostedsadresse.vegadresse[0].husnummer, + kafkaPerson.bostedsadresse.vegadresse[0].husbokstav + } + ); + person.INT_ResidentialZipCode__c = kafkaPerson.bostedsadresse.vegadresse[0].postnummer; + person.INT_AddressMunicipalityNumber__c = kafkaPerson.bostedsadresse.vegadresse[0].kommunenummer; + person.INT_AddressDistrictNumber__c = kafkaPerson.bostedsadresse.vegadresse[0].bydelsnummer; + person.INT_Coordinates__c = kafkaPerson.bostedsadresse.vegadresse[0].koordinater; + } else if (kafkaPerson.bostedsadresse.matrikkeladresse.size() > 0) { + person.INT_ResidentialZipCode__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].postnummer; + person.INT_AddressMunicipalityNumber__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].kommunenummer; + person.INT_AddressDistrictNumber__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].bydelsnummer; + person.INT_Coordinates__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].koordinater; + } + + // oppholdsadresser + // assumption: vegadresse has first pri, then utenlandskAdresse, then ukjentbosted + if (kafkaPerson.oppholdsadresse.vegadresse.size() > 0) { + person.INT_TemporaryAddress__c = addressCreator( + new List{ + kafkaPerson.oppholdsadresse.vegadresse[0].adressenavn, + kafkaPerson.oppholdsadresse.vegadresse[0].husnummer, + kafkaPerson.oppholdsadresse.vegadresse[0].husbokstav + } + ); + person.INT_TemporaryZipCode__c = kafkaPerson.oppholdsadresse.vegadresse[0].postnummer; + person.INT_TemporaryMunicipalityNumber__c = kafkaPerson.oppholdsadresse.vegadresse[0].kommunenummer; + person.INT_TemporaryCoordinates__c = kafkaPerson.oppholdsadresse.vegadresse[0].koordinater; + } else if (kafkaPerson.oppholdsadresse.matrikkeladresse.size() > 0) { + person.INT_TemporaryZipCode__c = kafkaPerson.oppholdsadresse.matrikkeladresse[0].postnummer; + person.INT_TemporaryMunicipalityNumber__c = kafkaPerson.oppholdsadresse.matrikkeladresse[0] + .kommunenummer; + person.INT_TemporaryCoordinates__c = kafkaPerson.oppholdsadresse.matrikkeladresse[0].koordinater; + } else if (kafkaPerson.oppholdsadresse.utenlandskAdresse.size() > 0) { + person.INT_TemporaryAddress__c = addressCreator( + new List{ + kafkaPerson.oppholdsadresse.utenlandskAdresse[0].adressenavnNummer, + kafkaPerson.oppholdsadresse.utenlandskAdresse[0].bygningEtasjeLeilighet, + kafkaPerson.oppholdsadresse.utenlandskAdresse[0].postboksNummerNavn, + kafkaPerson.oppholdsadresse.utenlandskAdresse[0].postkode, + kafkaPerson.oppholdsadresse.utenlandskAdresse[0].bysted, + kafkaPerson.oppholdsadresse.utenlandskAdresse[0].regionDistriktOmraade + } + ); // max 255 symbols might be an issue + person.INT_TemporaryCountryCode__c = kafkaPerson.oppholdsadresse.utenlandskAdresse[0].landkode.left(3); + } else if (kafkaPerson.oppholdsadresse.ukjentBosted.size() > 0) { + person.INT_TemporaryMunicipalityNumber__c = kafkaPerson.oppholdsadresse.ukjentBosted[0].bostedskommune; + } + } + } + + @TestVisible + private void setMunicipalityAndGT(Person__c person, KafkaPerson2 kafkaPerson) { + // Set GT Municipality and District numbers + if (kafkaPerson.kommunenummerFraGt != PDL_ERROR_STRING) { + person.INT_GTMunicipalityNumber__c = kafkaPerson.kommunenummerFraGt; + person.INT_RegionNumber__c = kafkaPerson.kommunenummerFraGt.left(2); + } + if (kafkaPerson.bydelsnummerFraGt != PDL_ERROR_STRING) { + person.INT_RegionNumber__c = kafkaPerson.bydelsnummerFraGt.left(2); + person.INT_GTDistrictNumber__c = kafkaPerson.bydelsnummerFraGt; + } + + // Set Municipality and District from GT if available, otherwise from Bostedsaddresse + if (person.INT_GTMunicipalityNumber__c != null) { + person.INT_MunicipalityNumber__c = person.INT_GTMunicipalityNumber__c; + } else if (person.INT_AddressMunicipalityNumber__c != null) { + person.INT_MunicipalityNumber__c = person.INT_AddressMunicipalityNumber__c; + } + if (person.INT_GTDistrictNumber__c != null) { + person.INT_DistrictNumber__c = person.INT_GTDistrictNumber__c; + } else if (person.INT_AddressDistrictNumber__c != null) { + person.INT_DistrictNumber__c = person.INT_AddressDistrictNumber__c; + } + } + + /** + * Return the date of death + * @param doedsfall list for KafkaPerson2.Doedsfall + * @return Date the first date we find or NULL + */ + @TestVisible + private Date getDoedsfall(List doedsfall) { + Map doedsfallMap = new Map(); + + for (KafkaPerson2.Doedsfall element : doedsfall) { + if (String.isNotBlank(element.doedsdato)) { + doedsfallMap.put(element.master.toUpperCase(), Date.valueOf(element.doedsdato)); + } else { + doedsfallMap.put(element.master, null); + } + } + + if (doedsfallMap.containsKey('PDL')) { + return doedsfallMap.get('PDL'); + } else if (doedsfallMap.containsKey('FREG')) { + return doedsfallMap.get('FREG'); + } + + return null; + } + + /** + * Safely transform collection into string compatible with multipicklist-fields. + * @param stringsToJoin Collection of strings to join + * @return Null or strings joined with ';' + */ + @TestVisible + private static String safelyJoinMultiPicklistString(List stringsToJoin) { + if (stringsToJoin == null || stringsToJoin.size() == 0) { + return null; + } else { + return String.join(stringsToJoin, ';'); + } + } + + /** + * Check that field size limitations of 255 signs is followed and allow empty string + * @param stringToCheck String to check + * @return Empty String checked string with maximum 255 symbols + */ + @TestVisible + private static String stringValidator(String stringToCheck) { + return String.isBlank(stringToCheck) || stringToCheck == null ? '' : stringToCheck.left(255); + } + + /** + * Check that date has a value (not null or '') + * @param dateToCheck Date to check + * @return Date + */ + @TestVisible + private static Date dateCreator(String dateToCheck) { + return !String.isBlank(dateToCheck) ? Date.valueOf(dateToCheck) : null; + } + + @TestVisible + private static String addressCreator(List addressFields) { + String addressString = ''; + for (String addressField : addressFields) { + if (stringValidator(addressField) != '') { + addressString += stringValidator(addressField) + ' '; + } + } + return addressString.removeEnd(' '); + } + + /** + * Find the adressebeskyttelse with the strictest security criteria + * @param values + * @return The list value with the strictest security criteria + */ + private String setClearanceLevel(List values) { + Integer grade = 0; + String returnGrade = 'UGRADERT'; + for (String s : values) { + if (ADR_BESKYTTELSES_GRADERING.containsKey(s) && ADR_BESKYTTELSES_GRADERING.get(s) > grade) { + grade = ADR_BESKYTTELSES_GRADERING.get(s); + returnGrade = s; + } + } + return returnGrade; + } + + /** + * Validate list sizes and if errors are found, throw error to store on the relevant Kafka Message + * @param kafkaPerson Kafka person to validate + */ + // prettier-ignore + private void validateListSizes(KafkaPerson2 kafkaPerson) { + List objectsFailingValidation = new List(); + + + if(kafkaPerson.identer == null) { + if (kafkaPerson.folkeregisterId.size() == 0) { throw new pdlMissingEntryException('No folkeregisterId found'); } + if (kafkaPerson.folkeregisterpersonstatus.size() == 0) { throw new pdlMissingEntryException('No folkeregisterpersonstatus found'); } + } else { + if (kafkaPerson.identer.size() == 0) { throw new pdlMissingEntryException('No idents found'); } + } + + if (kafkaPerson.navn.size() == 0) { throw new pdlMissingEntryException('No name found'); } + if (kafkaPerson.navn[0].etternavn == null) {throw new pdlMissingEntryException('No etternavn found'); } + + // Check for list sizes greater than one + if (kafkaPerson.bostedsadresse.vegadresse.size() > 1) { objectsFailingValidation.add('bostedsadresse.vegadresse'); } + if (kafkaPerson.bostedsadresse.matrikkeladresse.size() > 1) { objectsFailingValidation.add('bostedsadresse.matrikkeladresse'); } + if (kafkaPerson.bostedsadresse.utenlandskAdresse.size() > 1) { objectsFailingValidation.add('bostedsadresse.utenlandskAdresse'); } + if (kafkaPerson.bostedsadresse.ukjentBosted.size() > 1) { objectsFailingValidation.add('bostedsadresse.ukjentBosted'); } + if (kafkaPerson.oppholdsadresse.vegadresse.size() > 1) { objectsFailingValidation.add('oppholdsadresse.vegadresse'); } + if (kafkaPerson.oppholdsadresse.matrikkeladresse.size() > 1) { objectsFailingValidation.add('oppholdsadresse.matrikkeladresse'); } + if (kafkaPerson.oppholdsadresse.utenlandskAdresse.size() > 1) { objectsFailingValidation.add('oppholdsadresse.utenlandskAdresse'); } + if (kafkaPerson.oppholdsadresse.ukjentBosted.size() > 1) { objectsFailingValidation.add('oppholdsadresse.ukjentBosted'); } + + if (objectsFailingValidation.size() > 0) { + throw new pdlListContainsTooManyEntriesException( + 'Multiple objects received for ' + + String.join(objectsFailingValidation, ',') + ); + } + } + /** + * Create map from ISO country codes to English Country Label + * @param commonCodeList List Common_Code__c records + * @return map from ISO code to country in English + */ + @TestVisible + private static Map createIsoMap(List commonCodeList) { + Map isoMap = new Map(); + for (Common_Code__c ccl : commonCodeList) { + isoMap.put(ccl.CRM_Code__c, ccl); + } + return isoMap; + } + + /** + * Takes ISO code value and gives country name in return + * @param isoCode ISO-code. either ISO 2 or ISO 3 standard + * @return country in English + */ + @TestVisible + private String getCountryNameFromIso(String isoCode) { + Common_Code__c country = getCountryFromIso(isoCode); + return country == null ? isoCode : country.Name; + } + + /** + * Takes ISO code value and gives country value in return + * @param isoCode ISO-code. either ISO 2 or ISO 3 standard + * @return country in English + */ + @TestVisible + private Id getCountryIdFromIso(String isoCode) { + Common_Code__c country = getCountryFromIso(isoCode); + return country == null ? null : country.Id; + } + + /** + * Takes ISO code value and gives country value in return + * @param isoCode ISO-code. either ISO 2 or ISO 3 standard + * @return country in English + */ + @TestVisible + private Common_Code__c getCountryFromIso(String isoCode) { + if (ISO_MAP.containsKey(isoCode)) { + return ISO_MAP.get(isoCode); + } + + if (String.isNotBlank(isoCode)) { + logger.error( + 'Error getting country from ISO Code.' + + '\n ISO Code: ' + + isoCode, + null, + CRM_ApplicationDomain.domain.NKS + ); + } + return null; + } + + /** + * @param citizenships ISO countrycodes (list) + * + * @return country names joined with ';' + */ + @TestVisible + private String crateCitizenshipString(List citizenships) { + String citizenshipReturnString = ''; + for (String citizenship : citizenships) { + citizenshipReturnString = citizenshipReturnString + (getCountryNameFromIso(citizenship)) + ';'; + } + + return citizenshipReturnString.removeEnd(';'); + } + + @TestVisible + private static void setIdents(KafkaPerson2 kafkaPerson, Person__c person) { + person.INT_NPID__c = Pdl_IdentUtility.getIdentsFromList(kafkaPerson.identer).npid; + setFolkeregisterIdents(kafkaPerson.folkeregisteridentifikator, person); + } + + private static void setFolkeregisterIdents( + PDL_FolkeregisterIdentifikator[] folkeregisterIdentifikator, + Person__c person + ) { + for (PDL_FolkeregisterIdentifikator identifikator : folkeregisterIdentifikator) { + if (String.isBlank(identifikator.identifikasjonsnummer)) { + continue; + } + + switch on identifikator.type { + when DNR { + if (String.isBlank(person.INT_dnr__c) || identifikator.metadata.historisk == false) { + person.INT_dnr__c = identifikator.identifikasjonsnummer; + } + continue; + } + when FNR { + if (identifikator.metadata.historisk == false && identifikator.status == PDL_IdentStatus.I_BRUK) { + person.INT_fnr__c = identifikator.identifikasjonsnummer; + } + continue; + } + } + } + } + /** + * Sets the Name field to one of valid idents with priority: FOLKEREGISTERIDENT, NPID, AKTORID + * if the list does not include valid idents - throwing exception + */ + @TestVisible + private static void setName(KafkaPerson2 kfkPerson, Person__c person) { + List identer = new List(kfkPerson.identer); + String flkId; + String npId; + for (PDL_IdentInformasjon ident : identer) { + if (ident.historisk == false) { + switch on ident.gruppe { + when FOLKEREGISTERIDENT { + flkId = ident.ident; + } + when NPID { + npId = ident.ident; + } + } + } + } + person.Name = (String.isNotBlank(flkId)) ? flkId : ((String.isNotBlank(npId) ? npId : null)); + if (String.isBlank(person.Name)) + throw new PdlIdentException('Not able to set any person idents from Kafka'); + } + + /** + * Sets empty value for all Person__c fields + * @param person record to modify + */ + @TestVisible + private static void emptyPersonFieldValues(Person__c person) { + List intFields = new List{ + 'INT_AddressDistrictNumber__c', + 'INT_AddressMunicipalityNumber__c', + 'INT_Citizenships__c', + 'INT_Confidential__c', + 'INT_Coordinates__c', + 'INT_DateOfBirth__c', + 'INT_DateOfDeath__c', + 'INT_DistrictNumber__c', + 'INT_dnr__c', + 'INT_FamilyRelations__c', + 'INT_FirstName__c', + 'INT_fnr__c', + 'INT_GTDistrictNumber__c', + 'INT_GTMunicipalityNumber__c', + 'INT_GuardianshipOrFuturePowerOfAttorney__c', + 'INT_LastName__c', + 'INT_LegalStatus__c', + 'INT_MaritalRelation__c', + 'INT_MaritalStatus__c', + 'INT_MaritalStatusDate__c', + 'INT_MiddleName__c', + 'INT_MovedFromCountry__c', + 'INT_MovedFromPlace__c', + 'INT_MovedToCountry__c', + 'INT_MovedToPlace__c', + 'INT_MunicipalityNumber__c', + 'INT_npid__c', + 'INT_Phone1__c', + 'INT_Phone2__c', + 'INT_PowerOfAttorney__c', + 'INT_RegionNumber__c', + 'INT_ResidentialAddress__c', + 'INT_ResidentialZipCode__c', + 'INT_SecurityMeasures__c', + 'INT_Sex__c', + 'INT_SpokenLanguageIntepreter__c', + 'INT_TemporaryAddress__c', + 'INT_TemporaryCoordinates__c', + 'INT_TemporaryCountryCode__c', + 'INT_TemporaryMunicipalityNumber__c', + 'INT_TemporaryZipCode__c' + }; + for (String intField : intFields) { + person.put(intField, null); + } + + //Set field value to false + for (String boolField : new List{ 'INT_IsDeceased__c' }) { + person.put(boolField, false); + } + } + + /** + * Sets empty value for all Person__c fields except idents + * @param person record to modify + */ + @TestVisible + private static void emptyTombstonePerson(Person__c person) { + List intFields = new List{ + 'INT_AddressDistrictNumber__c', + 'INT_AddressMunicipalityNumber__c', + 'INT_BankAccountNumber__c', + 'INT_BankAccountNumberLastModified__c', + 'INT_Citizenships__c', + 'INT_Confidential__c', + 'INT_Coordinates__c', + 'INT_DateOfBirth__c', + 'INT_DateOfDeath__c', + 'INT_DistrictNumber__c', + 'INT_FamilyRelations__c', + 'INT_FirstName__c', + 'INT_GTDistrictNumber__c', + 'INT_GTMunicipalityNumber__c', + 'INT_GuardianshipOrFuturePowerOfAttorney__c', + 'INT_KrrEmail__c', + 'INT_KrrIntegrationStatus__c', + 'INT_KrrMobilePhone__c', + 'INT_LastName__c', + 'INT_LastUpdatedFromKRR__c', + 'INT_LegalStatus__c', + 'INT_MaritalRelation__c', + 'INT_MaritalStatus__c', + 'INT_MaritalStatusDate__c', + 'INT_MiddleName__c', + 'INT_MovedFromCountry__c', + 'INT_MovedFromPlace__c', + 'INT_MovedToCountry__c', + 'INT_MovedToPlace__c', + 'INT_MunicipalityNumber__c', + 'INT_NavEmployeeFromDateTime__c', + 'INT_NavEmployeeToDateTime__c', + 'INT_Phone1__c', + 'INT_Phone2__c', + 'INT_PowerOfAttorney__c', + 'INT_RegionNumber__c', + 'INT_ResidentialAddress__c', + 'INT_ResidentialZip__c', + 'INT_ResidentialZipCode__c', + 'INT_SecurityMeasures__c', + 'INT_Sex__c', + 'INT_SpokenLanguageIntepreter__c', + 'INT_TemporaryAddress__c', + 'INT_TemporaryCoordinates__c', + 'INT_TemporaryCountryCode__c', + 'INT_TemporaryMunicipalityNumber__c', + 'INT_TemporaryZipCode__c', + 'INT_VerifiedFromKRR__c' + }; + for (String intField : intFields) { + person.put(intField, null); + } + + //Set field value to false + for ( + String boolField : new List{ 'INT_IsDeceased__c', 'INT_IsNavEmployee__c', 'INT_KRR_Reservation__c' } + ) { + person.put(boolField, false); + } + } + + private void setMessageError(String errorMsg, KafkaMessage__c message) { + String decodedValue = KafkaMessageUtils.base64ULSafeDecode(message.CRM_Key__c).toString(); + Key key = (Key) System.JSON.deserialize(decodedValue, Key.class); + + if (existingActors != null && existingActors.contains(key.aktoer_id)) { + setMessageError(errorMsg, message, KafkaMessageService.STATUS_ERROR); + } else { + setMessageError(errorMsg, message, KafkaMessageService.STATUS_WARNING); + } + } + + private void setMessageError(String errorMsg, KafkaMessage__c message, String status) { + message.CRM_ErrorMessage__c = errorMsg.mid(0, 255); //Handle if the total error message exceeds 255 characters + message.CRM_Status__c = status; + } + + private Key getKeyFromBase64(String encodedString) { + return (Key) System.JSON.deserialize( + KafkaMessageUtils.base64ULSafeDecode(encodedString).toString(), + Key.class + ); + } + + private class Key { + final String aktoer_id; + final Boolean tombstone; + } + + public class PdlListContainsTooManyEntriesException extends Exception { + } + + public class PdlMissingEntryException extends Exception { + } + + public class PdlIdentException extends Exception { + } +} diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls-meta.xml b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls new file mode 100644 index 00000000..b01dee9b --- /dev/null +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -0,0 +1,1511 @@ +@IsTest +private with sharing class KafkaPdlPersondokumentHandlerTest { + @TestSetup + static void makeData() { + // record for setting correct Country from Country ISO code + List commonCodes = new List(); + + Common_Code__c ccIND = new Common_Code__c(); + ccIND.Name = 'India'; + ccIND.CRM_Code_Set__c = 'Landkoder'; + ccIND.CRM_Code__c = 'IND'; + ccIND.CRM_Active__c = true; + commonCodes.add(ccIND); + + Common_Code__c ccNOR = new Common_Code__c(); + ccNOR.Name = 'Norge'; + ccNOR.CRM_Code_Set__c = 'Landkoder'; + ccNOR.CRM_Code__c = 'NOR'; + ccNOR.CRM_Active__c = true; + commonCodes.add(ccNOR); + + insert commonCodes; + } + + /********************* + * TESTS FOR ISO MAP * + *********************/ + + @IsTest + static void createIsoMapTest() { + Test.startTest(); + System.assertEquals( + 2, + KafkaPDLHandler2.createIsoMap( + [ + SELECT Name, CRM_Code__c + FROM Common_Code__c + WHERE CRM_Active__c = TRUE AND CRM_Code_Set__c IN ('Landkoder', 'LandkoderISO2') + ] + ) + .size(), + 'Expected two values' + ); + Test.stopTest(); + } + + @IsTest + static void getCountryFromIsoReturnNull() { + Test.startTest(); + System.assertEquals(null, new KafkaPDLHandler2().getCountryFromIso(null), 'Expected null in return'); + Test.stopTest(); + } + + @IsTest + static void getCountryFromIsoReturnCommonCode() { + Test.startTest(); + System.assertNotEquals(null, new KafkaPDLHandler2().getCountryFromIso('NOR'), 'Expected null in return'); + Test.stopTest(); + } + + @IsTest + static void getCountryNameFromIso() { + Test.startTest(); + System.assertEquals('Norge', new KafkaPDLHandler2().getCountryNameFromIso('NOR'), 'Expected Norge in return'); + Test.stopTest(); + } + + @IsTest + static void getCountrySfIdFromIso() { + Test.startTest(); + System.assertNotEquals( + null, + new KafkaPDLHandler2().getCountryIdFromIso('NOR'), + 'Did not expected null in return' + ); + Test.stopTest(); + } + + @IsTest + static void crateCitizenshipStringTest() { + Test.startTest(); + System.assertEquals( + 'Norge;India', + new KafkaPDLHandler2().crateCitizenshipString(new List{ 'NOR', 'IND' }), + 'Expected list with Norge and India' + ); + Test.stopTest(); + } + + /******************************************* + * TESTS FOR idents * + *******************************************/ + @isTest + static void setNameTest() { + KafkaPerson2 kPerson = createBaseKafkaPerson('1234567890123'); + + kPerson.identer.add(new PDL_IdentInformasjon()); + kPerson.identer[0].ident = '12345678901'; + kPerson.identer[0].historisk = false; + kPerson.identer[0].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + + kPerson.identer.add(new PDL_IdentInformasjon()); + kPerson.identer[1].ident = '12345678911'; + kPerson.identer[1].historisk = false; + kPerson.identer[1].gruppe = PDL_IdentGruppe.NPID; + + kPerson.identer.add(new PDL_IdentInformasjon()); + kPerson.identer[2].ident = '52345678901'; + kPerson.identer[2].historisk = false; + kPerson.identer[2].gruppe = PDL_IdentGruppe.AKTORID; + + kPerson.identer.add(new PDL_IdentInformasjon()); + kPerson.identer[3].ident = '12345678902'; + kPerson.identer[3].historisk = true; + kPerson.identer[3].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + + Person__c person = new Person__c(); + + KafkaPDLHandler2.setName(kPerson, person); + + System.assertEquals('12345678901', person.Name, 'Expected non historisk FOLKEREGISTERIDENT'); + + person = new Person__c(); + kPerson.identer[0].historisk = true; + KafkaPDLHandler2.setName(kPerson, person); + + System.assertEquals('12345678911', person.Name, 'Expected non historisk NPID'); + } + + @IsTest + static void setNameException() { + KafkaPerson2 kPerson = createBaseKafkaPerson('1234567890123'); + + kPerson.identer.add(new PDL_IdentInformasjon()); + kPerson.identer[0].ident = '12345678901'; + kPerson.identer[0].historisk = true; + kPerson.identer[0].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + + kPerson.identer.add(new PDL_IdentInformasjon()); + kPerson.identer[1].ident = '12345678911'; + kPerson.identer[1].historisk = true; + kPerson.identer[1].gruppe = PDL_IdentGruppe.NPID; + + kPerson.identer.add(new PDL_IdentInformasjon()); + kPerson.identer[2].ident = '52345678901'; + kPerson.identer[2].historisk = false; + kPerson.identer[2].gruppe = PDL_IdentGruppe.AKTORID; + + kPerson.identer.add(new PDL_IdentInformasjon()); + kPerson.identer[3].ident = '12345678902'; + kPerson.identer[3].historisk = true; + kPerson.identer[3].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + + Person__c person = new Person__c(); + + Test.startTest(); + try { + KafkaPDLHandler2.setName(kPerson, person); + System.assert(false, 'No exception thrown'); + } catch (KafkaPDLHandler2.PdlIdentException ex) { + System.assert(true); + } catch (Exception e) { + System.assert(false, 'Did not catch the correct exception'); + } + Test.stopTest(); + } + + @IsTest + static void setIdentsTest() { + KafkaPerson2 kPerson = createBaseKafkaPerson('1234567890123'); + + kPerson.identer.add(new PDL_IdentInformasjon()); + kPerson.identer[0].ident = '12345678901'; + kPerson.identer[0].historisk = false; + kPerson.identer[0].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + + kPerson.identer.add(new PDL_IdentInformasjon()); + kPerson.identer[1].ident = '12345678911'; + kPerson.identer[1].historisk = false; + kPerson.identer[1].gruppe = PDL_IdentGruppe.NPID; + + kPerson.identer.add(new PDL_IdentInformasjon()); + kPerson.identer[2].ident = '52345678901'; + kPerson.identer[2].historisk = true; + kPerson.identer[2].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + + kPerson.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); + kPerson.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; + kPerson.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; + kPerson.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; + kPerson.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); + kPerson.folkeregisteridentifikator[0].metadata.historisk = false; + + kPerson.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); + kPerson.folkeregisteridentifikator[1].identifikasjonsnummer = '52345678901'; + kPerson.folkeregisteridentifikator[1].status = PDL_IdentStatus.OPPHOERT; + kPerson.folkeregisteridentifikator[1].type = PDL_IdentType.DNR; + kPerson.folkeregisteridentifikator[1].metadata = new PDL_Metadata(); + kPerson.folkeregisteridentifikator[1].metadata.historisk = true; + + Person__c person = new Person__c(); + + Test.startTest(); + KafkaPDLHandler2.setIdents(kPerson, person); + Test.stopTest(); + + System.assertEquals(null, person.INT_ACTORID__c, 'Expected AKTORID to be null'); + System.assertEquals('12345678901', person.INT_FNR__c, 'Expected FNR to be set'); + System.assertEquals('12345678911', person.INT_NPID__c, 'Expect NPID to be set'); + System.assertEquals('52345678901', person.INT_DNR__c, 'Expect DNR to be set'); + } + + /******************************************* + * TESTS FOR checkLastUpdatedAndTombStones * + *******************************************/ + + //SCENARIO: + // A Person exists in Salesforce and we try to process a KafkaMessage__c where the CreatedDate is older than the Person LastModifiedDate + // KafkaMessage__c.CRM_Status__c should be set to error + @IsTest + static void checkLastUpdatedAndTombStonesOlderMessages() { + Person__c person1 = new Person__c(); + person1.INT_ActorId__c = '1000012345678'; + person1.Name = '20000000000'; + person1.INT_fnr__c = '20000000000'; + person1.INT_LastUpdatedFromPDL__c = Datetime.now(); + insert person1; + + String createdDate = Datetime.now().addDays(-2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + KafkaMessage__c msg = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate + + '"}', + KafkaMessage__c.class + ); + msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; + msg.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":false}')); + + Test.startTest(); + new KafkaPDLHandler2().checkLastUpdatedAndTombStones(new List{ msg }); + Test.stopTest(); + + System.assertEquals( + KafkaMessageService.STATUS_WARNING, + msg.CRM_Status__c, + 'Expected the status to be set to error' + ); + } + + //SCENARIO: + // A Person exists in Salesforce and we try to process a KafkaMessage__c where the persons INT_LastUpdatedFromPDL__c is empty + // KafkaMessage__c.CRM_Status__c should not be updated + @IsTest + static void checkLastUpdatedAndTombStonesNewMessagesNoLastUpdated() { + Person__c person1 = new Person__c(); + person1.INT_ActorId__c = '1000012345678'; + person1.Name = '20000000000'; + person1.INT_fnr__c = '20000000000'; + person1.INT_LastUpdatedFromPDL__c = null; + insert person1; + + String createdDate = Datetime.now().addDays(2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + KafkaMessage__c msg = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate + + '"}', + KafkaMessage__c.class + ); + msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; + msg.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":false}')); + + Test.startTest(); + new KafkaPDLHandler2().checkLastUpdatedAndTombStones(new List{ msg }); + Test.stopTest(); + + System.assertEquals( + KafkaMessageService.STATUS_PENDING, + msg.CRM_Status__c, + 'Expected the status to be the same' + ); + } + + //SCENARIO: + // A Person exists in Salesforce and we try to process a KafkaMessage__c where the CreatedDate is after than the Person INT_LastUpdatedFromPDL__c + // KafkaMessage__c.CRM_Status__c should not be updated + @IsTest + static void checkLastUpdatedAndTombStonesNewMessages() { + Person__c person1 = new Person__c(); + person1.INT_ActorId__c = '1000012345678'; + person1.Name = '20000000000'; + person1.INT_fnr__c = '20000000000'; + person1.INT_LastUpdatedFromPDL__c = Datetime.now(); + insert person1; + + String createdDate = Datetime.now().addDays(2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + KafkaMessage__c msg = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate + + '"}', + KafkaMessage__c.class + ); + msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; + msg.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":false}')); + + Test.startTest(); + new KafkaPDLHandler2().checkLastUpdatedAndTombStones(new List{ msg }); + Test.stopTest(); + + System.assertEquals( + KafkaMessageService.STATUS_PENDING, + msg.CRM_Status__c, + 'Expected the status to be the same' + ); + } + + //SCENARIO: + // We try to process a KafkaMessage__c where we don't have any matching person in Salesforce + // KafkaMessage__c.CRM_Status__c should not be updated + @IsTest + static void checkLastUpdatedAndTombStonesBrandNewMessages() { + String createdDate = Datetime.now().addDays(2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + KafkaMessage__c msg = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate + + '"}', + KafkaMessage__c.class + ); + msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; + msg.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":false}')); + + Test.startTest(); + new KafkaPDLHandler2().checkLastUpdatedAndTombStones(new List{ msg }); + Test.stopTest(); + + System.assertEquals( + KafkaMessageService.STATUS_PENDING, + msg.CRM_Status__c, + 'Expected the status to be the same' + ); + } + + //SCENARIO: + // We try to process several KafkaMessage__c where they all have the same key and matches a Person in Salesforce + // KafkaMessage__c.CRM_Status__c should be set to processec on only the oldest + @IsTest + static void checkLastUpdatedAndTombStonesNewDuplicateMessages() { + Person__c person1 = new Person__c(); + person1.INT_ActorId__c = '1000012345678'; + person1.Name = '20000000000'; + person1.INT_fnr__c = '20000000000'; + person1.INT_LastUpdatedFromPDL__c = Datetime.now(); + insert person1; + + String createdDate1 = Datetime.now().addDays(2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + String createdDate2 = Datetime.now().addDays(3).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + String createdDate3 = Datetime.now().addDays(1).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + String createdDate4 = Datetime.now().addDays(-2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + + KafkaMessage__c msg1 = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate1 + + '"}', + KafkaMessage__c.class + ); + msg1.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg1.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; + msg1.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":false}')); + + // The newest + KafkaMessage__c msg2 = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate2 + + '"}', + KafkaMessage__c.class + ); + msg2.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg2.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; + msg2.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":false}')); + + KafkaMessage__c msg3 = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate3 + + '"}', + KafkaMessage__c.class + ); + msg3.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg3.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; + msg3.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":false}')); + + KafkaMessage__c msg4 = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate4 + + '"}', + KafkaMessage__c.class + ); + msg4.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg4.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; + msg4.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":false}')); + + Test.startTest(); + new KafkaPDLHandler2().checkLastUpdatedAndTombStones(new List{ msg1, msg2, msg3, msg4 }); + Test.stopTest(); + + System.assertEquals( + KafkaMessageService.STATUS_PENDING, + msg1.CRM_Status__c, + 'Expected the status to be processed' + ); + System.assertEquals( + KafkaMessageService.STATUS_PENDING, + msg2.CRM_Status__c, + 'Expected the status to be the same' + ); + System.assertEquals( + KafkaMessageService.STATUS_PENDING, + msg3.CRM_Status__c, + 'Expected the status to be processed' + ); + System.assertEquals(KafkaMessageService.STATUS_WARNING, msg4.CRM_Status__c, 'Expected the status to be error'); + } + + //SCENARIO: + // We try to process two several KafkaMessage__c where they all have the same actorId that matches a Person in Salesforce, but one is a tombstone + // Both KafkaMessage__c should be processed + @IsTest + static void checkLastUpdatedAndTombStonesDuplicateMessagesWithTombstone() { + Person__c person1 = new Person__c(); + person1.INT_ActorId__c = '1000012345678'; + person1.Name = '20000000000'; + person1.INT_fnr__c = '20000000000'; + person1.INT_LastUpdatedFromPDL__c = Datetime.now(); + insert person1; + + String createdDate1 = Datetime.now().addDays(1).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + String createdDate2 = Datetime.now().addDays(2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + + KafkaMessage__c msg1 = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate1 + + '"}', + KafkaMessage__c.class + ); + msg1.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg1.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; + msg1.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":false}')); + + // The newest + KafkaMessage__c msg2 = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate2 + + '"}', + KafkaMessage__c.class + ); + msg2.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg2.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; + msg2.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":true}')); + + Test.startTest(); + new KafkaPDLHandler2().checkLastUpdatedAndTombStones(new List{ msg1, msg2 }); + Test.stopTest(); + + System.assertEquals( + KafkaMessageService.STATUS_WARNING, + msg1.CRM_Status__c, + 'Expected the status to be warning' + ); + System.assertEquals( + KafkaMessageService.STATUS_PENDING, + msg2.CRM_Status__c, + 'Expected the status to be pending' + ); + } + + //SCENARIO: + // We try process a KafkaMessage__c where we dont have a match a Person in Salesforce, but one is a tombstone + // KafkaMessage__c.CRM_Status__c should be set to processed + @IsTest + static void checkLastUpdatedAndTombStonesBrandNewMessagesWithTombstone() { + String createdDate1 = Datetime.now().addDays(1).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + + KafkaMessage__c msg1 = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate1 + + '"}', + KafkaMessage__c.class + ); + msg1.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg1.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; + msg1.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":true}')); + + Test.startTest(); + new KafkaPDLHandler2().checkLastUpdatedAndTombStones(new List{ msg1 }); + Test.stopTest(); + + System.assertEquals( + KafkaMessageService.STATUS_PROCESSED, + msg1.CRM_Status__c, + 'Expected the status to be processed' + ); + } + + //SCENARIO: + // We try process a KafkaMessage__c where we have a match a Person in Salesforce, the message is a tombstone and the value is null + // Person should get a tombstone + @IsTest + static void processTombstoneTest() { + insert new Person__c( + Name = '12345678901', + INT_fnr__c = '12345678901', + INT_ActorId__c = '1000012345678', + INT_FirstName__c = 'FNAME', + INT_LastName__c = 'LNAME' + ); + + List kafkaMessages = new List(); + kafkaMessages.add( + new KafkaMessage__c( + CRM_Topic__c = 'teamnks.nks-sf-pdl-v3', + CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":true}')), + CRM_Value__c = null + ) + ); + + // Verify that we have only one Account + System.assertEquals(1, [SELECT COUNT() FROM Person__c]); + + // Act + Test.startTest(); + insert kafkaMessages; + System.debug([SELECT Id, CRM_Topic__c, CRM_Key__c, CRM_ErrorMessage__c FROM KafkaMessage__c]); + AsyncRequestSchedulable.enqueueAsyncJobs(); + Test.stopTest(); + System.debug([SELECT Id, CRM_Topic__c, CRM_Key__c, CRM_ErrorMessage__c FROM KafkaMessage__c]); + + // Assert that 1 Person Accounts have been inserted + System.assertEquals(1, [SELECT COUNT() FROM Person__c]); + + // Assert that all Kafka Message records have been marked as processed + System.assertEquals( + 1, + [SELECT COUNT() FROM KafkaMessage__c WHERE CRM_Status__c = :KafkaMessageService.STATUS_PROCESSED] + ); + + Person__c p = [ + SELECT Id, INT_ActorId__c, INT_fnr__c, Name, INT_IsHasTombstone__c, INT_FirstName__c, INT_LastName__c + FROM Person__c + LIMIT 1 + ]; + + // Assert that only tombstone and id fields has values + System.assertEquals('1000012345678', p.INT_ActorId__c, 'ActorId'); + System.assertEquals('12345678901', p.INT_fnr__c, 'fnr'); + System.assertEquals('12345678901', p.Name, 'Name'); + System.assertEquals(true, p.INT_IsHasTombstone__c, 'Tombstone'); + System.assertEquals(null, p.INT_FirstName__c, 'Firstname'); + System.assertEquals(null, p.INT_LastName__c, 'Lastname'); + } + + /******************************** + * TESTS FOR message processing * + ********************************/ + + @isTest + static void insertKafkaMessageOldVersion() { + KafkaPerson2 kafkaPerson = createBaseKafkaPersonOld('11223344556'); + kafkaPerson.folkeregisterId.add('12345678901'); + + KafkaMessage__c message = createKafkaMessageHelper(kafkaPerson, '11223344556', false); + + // Verify that we don't have any Person__c records + System.assertEquals(0, [SELECT COUNT() FROM Person__c]); + + // Act + Test.startTest(); + insert message; + AsyncRequestSchedulable.enqueueAsyncJobs(); + Test.stopTest(); + + isKafkaMessageProcessed( + [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message.Id LIMIT 1] + ); + + System.assertEquals(1, [SELECT COUNT() FROM Person__c]); + Person__c person = [ + SELECT FIELDS(STANDARD), INT_ActorId__c, INT_fnr__c, INT_dnr__c, INT_npid__c + FROM Person__c + WHERE INT_actorId__c = '11223344556' + ]; + + System.assertEquals(null, person.INT_fnr__c, 'Did not expect this value to be set'); + System.assertEquals(null, person.INT_npid__c, 'Did not expect this value to be set'); + System.assertEquals(null, person.INT_dnr__c, 'Did not expect this value to be set'); + System.assertEquals('12345678901', person.Name, 'Expected NAME to be set'); + System.assertEquals('11223344556', person.INT_actorId__c, 'Expected AKTØR ID to be set'); + } + + @isTest + static void insertKafkaMessageDefault() { + KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); + kafkaPerson.identer.add(new PDL_IdentInformasjon()); + kafkaPerson.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + kafkaPerson.identer[1].historisk = false; + kafkaPerson.identer[1].ident = '12345678901'; + kafkaPerson.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); + kafkaPerson.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; + kafkaPerson.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; + kafkaPerson.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; + kafkaPerson.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); + kafkaPerson.folkeregisteridentifikator[0].metadata.historisk = false; + + KafkaMessage__c message = createKafkaMessageHelper(kafkaPerson, '11223344556', false); + + // Verify that we don't have any Person__c records + System.assertEquals(0, [SELECT COUNT() FROM Person__c]); + + // Act + Test.startTest(); + insert message; + AsyncRequestSchedulable.enqueueAsyncJobs(); + Test.stopTest(); + + isKafkaMessageProcessed( + [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message.Id LIMIT 1] + ); + + System.assertEquals(1, [SELECT COUNT() FROM Person__c]); + Person__c person = [ + SELECT FIELDS(STANDARD), INT_ActorId__c, INT_fnr__c, INT_dnr__c, INT_npid__c + FROM Person__c + WHERE INT_actorId__c = '11223344556' + ]; + + System.assertEquals('12345678901', person.INT_fnr__c, 'Expect FNR to be set'); + System.assertEquals(null, person.INT_npid__c, 'Did not expect this value to be set'); + System.assertEquals(null, person.INT_dnr__c, 'Did not expect this value to be set'); + System.assertEquals('12345678901', person.Name, 'Expected NAME to be set'); + System.assertEquals('11223344556', person.INT_actorId__c, 'Expected AKTØR ID to be set'); + } + + @isTest + static void insertKafkaMessageProcessed() { + KafkaPerson2 kafkaPerson1 = createBaseKafkaPerson('11223344556'); + kafkaPerson1.identer.add(new PDL_IdentInformasjon()); + kafkaPerson1.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + kafkaPerson1.identer[1].historisk = false; + kafkaPerson1.identer[1].ident = '12345678901'; + kafkaPerson1.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); + kafkaPerson1.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; + kafkaPerson1.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; + kafkaPerson1.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; + kafkaPerson1.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); + kafkaPerson1.folkeregisteridentifikator[0].metadata.historisk = false; + + KafkaPerson2 kafkaPerson2 = createBaseKafkaPerson('11223344556'); + kafkaPerson2.identer.add(new PDL_IdentInformasjon()); + kafkaPerson2.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + kafkaPerson2.identer[1].historisk = false; + kafkaPerson2.identer[1].ident = '12345678901'; + kafkaPerson2.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); + kafkaPerson2.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; + kafkaPerson2.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; + kafkaPerson2.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; + kafkaPerson2.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); + kafkaPerson2.folkeregisteridentifikator[0].metadata.historisk = false; + kafkaPerson2.sikkerhetstiltak = new List(); + kafkaPerson2.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); + kafkaPerson2.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); + kafkaPerson2.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); + + KafkaPerson2 kafkaPerson3 = createBaseKafkaPerson('11223344556'); + kafkaPerson3.identer.add(new PDL_IdentInformasjon()); + kafkaPerson3.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + kafkaPerson3.identer[1].historisk = false; + kafkaPerson3.identer[1].ident = '12345678901'; + kafkaPerson3.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); + kafkaPerson3.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; + kafkaPerson3.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; + kafkaPerson3.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; + kafkaPerson3.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); + kafkaPerson3.folkeregisteridentifikator[0].metadata.historisk = false; + + KafkaMessage__c message1 = createKafkaMessageHelper(createBaseKafkaPerson('11223344557'), '11223344557', true); + KafkaMessage__c message2 = createKafkaMessageHelper(kafkaPerson1, '11223344556', false); + KafkaMessage__c message3 = createKafkaMessageHelper(kafkaPerson2, '11223344556', false); + KafkaMessage__c message4 = createKafkaMessageHelper(kafkaPerson3, '11223344556', true); + + // Act + Test.startTest(); + insert new List{ message1, message2, message3, message4 }; + AsyncRequestSchedulable.enqueueAsyncJobs(); + Test.stopTest(); + + message1 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message1.Id]; + message2 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message2.Id]; + message3 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message3.Id]; + message4 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message4.Id]; + + System.assertEquals( + KafkaMessageService.STATUS_PROCESSED, + message1.CRM_Status__c, + '' + message1.CRM_ErrorMessage__c + ); + System.assertEquals( + KafkaMessageService.STATUS_WARNING, + message2.CRM_Status__c, + '' + message2.CRM_ErrorMessage__c + ); + System.assertEquals( + KafkaMessageService.STATUS_WARNING, + message3.CRM_Status__c, + '' + message3.CRM_ErrorMessage__c + ); + System.assertEquals( + KafkaMessageService.STATUS_PROCESSED, + message4.CRM_Status__c, + '' + message4.CRM_ErrorMessage__c + ); + System.assertEquals(0, [SELECT COUNT() FROM Person__c WHERE Name = '12345678901']); + } + + @isTest + static void insertKafkaMessageWarning() { + KafkaPerson2 kafkaPerson1 = createBaseKafkaPerson('11223344556'); + kafkaPerson1.identer.add(new PDL_IdentInformasjon()); + kafkaPerson1.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + kafkaPerson1.identer[1].historisk = false; + kafkaPerson1.identer[1].ident = '12345678901'; + kafkaPerson1.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); + kafkaPerson1.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; + kafkaPerson1.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; + kafkaPerson1.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; + kafkaPerson1.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); + kafkaPerson1.folkeregisteridentifikator[0].metadata.historisk = false; + + KafkaPerson2 kafkaPerson2 = createBaseKafkaPerson('11223344556'); + kafkaPerson2.identer.add(new PDL_IdentInformasjon()); + kafkaPerson2.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + kafkaPerson2.identer[1].historisk = false; + kafkaPerson2.identer[1].ident = '12345678901'; + kafkaPerson2.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); + kafkaPerson2.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; + kafkaPerson2.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; + kafkaPerson2.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; + kafkaPerson2.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); + kafkaPerson2.folkeregisteridentifikator[0].metadata.historisk = false; + kafkaPerson2.sikkerhetstiltak = new List(); + kafkaPerson2.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); + kafkaPerson2.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); + kafkaPerson2.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); + + KafkaMessage__c message1 = createKafkaMessageHelper(createBaseKafkaPerson('11223344557'), '11223344557', true); + KafkaMessage__c message2 = createKafkaMessageHelper(kafkaPerson1, '11223344556', false); + KafkaMessage__c message3 = createKafkaMessageHelper(kafkaPerson2, '11223344556', false); + + // Act + Test.startTest(); + insert new List{ message1, message2, message3 }; + AsyncRequestSchedulable.enqueueAsyncJobs(); + Test.stopTest(); + + message1 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message1.Id]; + message2 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message2.Id]; + message3 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message3.Id]; + + System.assertEquals( + KafkaMessageService.STATUS_PROCESSED, + message1.CRM_Status__c, + '' + message1.CRM_ErrorMessage__c + ); + System.assertEquals( + KafkaMessageService.STATUS_PROCESSED, + message2.CRM_Status__c, + '' + message2.CRM_ErrorMessage__c + ); + System.assertEquals( + KafkaMessageService.STATUS_WARNING, + message3.CRM_Status__c, + '' + message3.CRM_ErrorMessage__c + ); + System.assertEquals(0, [SELECT COUNT() FROM Person__c WHERE Name = '12345678901']); + } + + @isTest + static void insertKafkaMessageUpdateError() { + insert new Person__c( + Name = '12345678901', + INT_fnr__c = '12345678901', + INT_ActorId__c = '11223344556', + INT_FirstName__c = 'FNAME', + INT_LastName__c = 'LNAME' + ); + + KafkaPerson2 kafkaPerson1 = createBaseKafkaPerson('11223344556'); + kafkaPerson1.identer.add(new PDL_IdentInformasjon()); + kafkaPerson1.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + kafkaPerson1.identer[1].historisk = false; + kafkaPerson1.identer[1].ident = '12345678901'; + kafkaPerson1.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); + kafkaPerson1.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; + kafkaPerson1.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; + kafkaPerson1.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; + kafkaPerson1.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); + kafkaPerson1.folkeregisteridentifikator[0].metadata.historisk = false; + + KafkaPerson2 kafkaPerson2 = createBaseKafkaPerson('11223344556'); + kafkaPerson2.identer.add(new PDL_IdentInformasjon()); + kafkaPerson2.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + kafkaPerson2.identer[1].historisk = false; + kafkaPerson2.identer[1].ident = '12345678901'; + kafkaPerson2.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); + kafkaPerson2.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; + kafkaPerson2.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; + kafkaPerson2.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; + kafkaPerson2.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); + kafkaPerson2.folkeregisteridentifikator[0].metadata.historisk = false; + kafkaPerson2.sikkerhetstiltak = new List(); + kafkaPerson2.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); + kafkaPerson2.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); + kafkaPerson2.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); + + KafkaPerson2 kafkaPerson3 = createBaseKafkaPerson('11223344559'); + kafkaPerson3.identer.add(new PDL_IdentInformasjon()); + kafkaPerson3.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + kafkaPerson3.identer[1].historisk = false; + kafkaPerson3.identer[1].ident = '12345678902'; + kafkaPerson3.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); + kafkaPerson3.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; + kafkaPerson3.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; + kafkaPerson3.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678902'; + kafkaPerson3.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); + kafkaPerson3.folkeregisteridentifikator[0].metadata.historisk = false; + + KafkaMessage__c message1 = createKafkaMessageHelper(createBaseKafkaPerson('11223344551'), '11223344551', true); + KafkaMessage__c message2 = createKafkaMessageHelper(kafkaPerson1, '11223344556', false); + KafkaMessage__c message3 = createKafkaMessageHelper(createBaseKafkaPerson('11223344553'), '11223344553', true); + KafkaMessage__c message4 = createKafkaMessageHelper(kafkaPerson2, '11223344556', false); + KafkaMessage__c message5 = createKafkaMessageHelper(createBaseKafkaPerson('11223344552'), '11223344552', true); + KafkaMessage__c message6 = createKafkaMessageHelper(kafkaPerson3, '11223344559', false); + + // Act + Test.startTest(); + insert new List{ message1, message2, message3, message4, message5, message6 }; + AsyncRequestSchedulable.enqueueAsyncJobs(); + Test.stopTest(); + + message1 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message1.Id]; + message2 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message2.Id]; + message3 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message3.Id]; + message4 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message4.Id]; + message5 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message5.Id]; + message6 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message6.Id]; + + System.assertEquals( + KafkaMessageService.STATUS_PROCESSED, + message1.CRM_Status__c, + '' + message1.CRM_ErrorMessage__c + ); + System.assertEquals( + KafkaMessageService.STATUS_PROCESSED, + message2.CRM_Status__c, + '' + message2.CRM_ErrorMessage__c + ); + System.assertEquals( + KafkaMessageService.STATUS_PROCESSED, + message3.CRM_Status__c, + '' + message3.CRM_ErrorMessage__c + ); + System.assertEquals( + KafkaMessageService.STATUS_ERROR, + message4.CRM_Status__c, + '' + message4.CRM_ErrorMessage__c + ); + System.assertEquals( + KafkaMessageService.STATUS_PROCESSED, + message5.CRM_Status__c, + '' + message5.CRM_ErrorMessage__c + ); + System.assertEquals( + KafkaMessageService.STATUS_PROCESSED, + message6.CRM_Status__c, + '' + message6.CRM_ErrorMessage__c + ); + System.assertEquals(1, [SELECT COUNT() FROM Person__c WHERE Name = '12345678901']); + System.assertEquals(1, [SELECT COUNT() FROM Person__c WHERE Name = '12345678902']); + } + + @isTest + static void insertKafkaMessageNpidPerson() { + KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); + + kafkaPerson.identer.add(new PDL_IdentInformasjon()); + kafkaPerson.identer[1].gruppe = PDL_IdentGruppe.NPID; + kafkaPerson.identer[1].historisk = false; + kafkaPerson.identer[1].ident = '12345678901'; + + kafkaPerson.folkeregisterpersonstatus.clear(); + + KafkaMessage__c message = createKafkaMessageHelper(kafkaPerson, '11223344556', false); + + // Act + Test.startTest(); + insert message; + AsyncRequestSchedulable.enqueueAsyncJobs(); + Test.stopTest(); + + isKafkaMessageProcessed( + [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message.Id LIMIT 1] + ); + + System.assertEquals(1, [SELECT COUNT() FROM Person__c]); + + Person__c person = [ + SELECT FIELDS(STANDARD), INT_ActorId__c, INT_fnr__c, INT_dnr__c, INT_npid__c + FROM Person__c + WHERE INT_actorId__c = '11223344556' + ]; + + System.assertEquals(null, person.INT_fnr__c, 'Did not expect this value to be set'); + System.assertEquals('12345678901', person.INT_npid__c, 'Expect this value to be set'); + System.assertEquals(null, person.INT_dnr__c, 'Did not expect this value to be set'); + System.assertEquals('12345678901', person.Name, 'Expected NAME to be set'); + System.assertEquals('11223344556', person.INT_actorId__c, 'Expected AKTØR ID to be set'); + } + + @isTest + static void insertKafkaMessageNpidPersonFromNpidToFnr() { + KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); + + kafkaPerson.identer.add(new PDL_IdentInformasjon()); + kafkaPerson.identer[1].gruppe = PDL_IdentGruppe.NPID; + kafkaPerson.identer[1].historisk = false; + kafkaPerson.identer[1].ident = '12345678901'; + + kafkaPerson.folkeregisterpersonstatus.clear(); + + KafkaMessage__c message1 = createKafkaMessageHelper(kafkaPerson, '11223344556', false); + + kafkaPerson.identer.add(new PDL_IdentInformasjon()); + kafkaPerson.identer[2].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + kafkaPerson.identer[2].historisk = false; + kafkaPerson.identer[2].ident = '52345678901'; + + kafkaPerson.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); + kafkaPerson.folkeregisteridentifikator[0].identifikasjonsnummer = '52345678901'; + kafkaPerson.folkeregisteridentifikator[0].type = PDL_IdentType.DNR; + kafkaPerson.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; + kafkaPerson.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); + kafkaPerson.folkeregisteridentifikator[0].metadata.historisk = false; + + kafkaPerson.folkeregisterpersonstatus.add('bosatt'); + + KafkaMessage__c message2 = createKafkaMessageHelper(kafkaPerson, '11223344556', false); + + kafkaPerson.identer[2].historisk = true; + + kafkaPerson.identer.add(new PDL_IdentInformasjon()); + kafkaPerson.identer[3].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + kafkaPerson.identer[3].historisk = false; + kafkaPerson.identer[3].ident = '11345678901'; + + kafkaPerson.folkeregisteridentifikator[0].status = PDL_IdentStatus.OPPHOERT; + kafkaPerson.folkeregisteridentifikator[0].metadata.historisk = true; + + kafkaPerson.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); + kafkaPerson.folkeregisteridentifikator[1].identifikasjonsnummer = '11345678901'; + kafkaPerson.folkeregisteridentifikator[1].type = PDL_IdentType.FNR; + kafkaPerson.folkeregisteridentifikator[1].status = PDL_IdentStatus.I_BRUK; + kafkaPerson.folkeregisteridentifikator[1].metadata = new PDL_Metadata(); + kafkaPerson.folkeregisteridentifikator[1].metadata.historisk = false; + + KafkaMessage__c message3 = createKafkaMessageHelper(kafkaPerson, '11223344556', false); + + KafkaMessageService msgService; + Person__c person; + + // Act + Test.startTest(); + + //Message 1 + insert message1; + msgService = new KafkaMessageService(new List{ message1 }); + msgService.handleMessages(); + + isKafkaMessageProcessed( + [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message1.Id LIMIT 1] + ); + System.assertEquals(1, [SELECT COUNT() FROM Person__c]); + person = [ + SELECT FIELDS(STANDARD), INT_ActorId__c, INT_fnr__c, INT_dnr__c, INT_npid__c + FROM Person__c + WHERE INT_actorId__c = '11223344556' + ]; + System.assertEquals('11223344556', person.INT_actorId__c, 'Expected AKTØR ID to be set'); + System.assertEquals(null, person.INT_fnr__c, 'Did not expect FNR to be set'); + System.assertEquals('12345678901', person.INT_npid__c, 'Expected NPID to be set'); + System.assertEquals(null, person.INT_dnr__c, 'Did not expect DNR to be set'); + System.assertEquals('12345678901', person.Name, 'Expected NAME to be same as NPID'); + + //Message 2 + insert message2; + msgService = new KafkaMessageService(new List{ message2 }); + msgService.handleMessages(); + + isKafkaMessageProcessed( + [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message2.Id LIMIT 1] + ); + System.assertEquals(1, [SELECT COUNT() FROM Person__c]); + person = [ + SELECT FIELDS(STANDARD), INT_ActorId__c, INT_fnr__c, INT_dnr__c, INT_npid__c + FROM Person__c + WHERE INT_actorId__c = '11223344556' + ]; + System.assertEquals('11223344556', person.INT_actorId__c, 'Expected AKTØR ID to be set'); + System.assertEquals(null, person.INT_fnr__c, 'Did not expect FNR to be set'); + System.assertEquals('12345678901', person.INT_npid__c, 'Expected NPID to be set'); + System.assertEquals('52345678901', person.INT_dnr__c, 'Expected DNR to be set'); + System.assertEquals('52345678901', person.Name, 'Expected NAME to be same as DNR'); + + //Message 3 + insert message3; + msgService = new KafkaMessageService(new List{ message3 }); + msgService.handleMessages(); + + isKafkaMessageProcessed( + [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message3.Id LIMIT 1] + ); + System.assertEquals(1, [SELECT COUNT() FROM Person__c]); + person = [ + SELECT FIELDS(STANDARD), INT_ActorId__c, INT_fnr__c, INT_dnr__c, INT_npid__c + FROM Person__c + WHERE INT_actorId__c = '11223344556' + ]; + + System.assertEquals('11223344556', person.INT_actorId__c, 'Expected AKTØR ID to be set'); + System.assertEquals('11345678901', person.INT_fnr__c, 'Expected FNR to be set'); + System.assertEquals('12345678901', person.INT_npid__c, 'Expected NPID to be set'); + System.assertEquals('52345678901', person.INT_dnr__c, 'Expect DNR to be set'); + System.assertEquals('11345678901', person.Name, 'Expected NAME to be same as FNR'); + + Test.stopTest(); + } + + /*************************** + * VERIFY THE DATA MAPPING * + **************************/ + + @isTest + static void mapFieldValuesExcludingAddresses() { + KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); + kafkaPerson.identer.add(new PDL_IdentInformasjon()); + kafkaPerson.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + kafkaPerson.identer[1].historisk = false; + kafkaPerson.identer[1].ident = '12345678901'; + kafkaPerson.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); + kafkaPerson.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; + kafkaPerson.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; + kafkaPerson.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; + kafkaPerson.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); + kafkaPerson.folkeregisteridentifikator[0].metadata.historisk = false; + + kafkaPerson.navn[0].fornavn = 'TEST'; + kafkaPerson.navn[0].mellomnavn = 'T.'; + + kafkaPerson.foedselsdato.add('2020-02-25'); + + kafkaPerson.innflyttingTilNorge.add(new PDL_InnflyttingTilNorge()); + kafkaPerson.innflyttingTilNorge[0].fraflyttingsland = 'IND'; + kafkaPerson.innflyttingTilNorge[0].fraflyttingsstedIUtlandet = 'Delhi'; + + kafkaPerson.sikkerhetstiltak = new List(); + kafkaPerson.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); + kafkaPerson.sikkerhetstiltak[0].beskrivelse = 'Telefonisk utestengelse'; + kafkaPerson.sikkerhetstiltak[0].tiltaksType = 'TFUS'; + kafkaPerson.sikkerhetstiltak[0].gyldigFraOgMed = '2020-12-14'; + kafkaPerson.sikkerhetstiltak[0].gyldigTilOgMed = '2020-12-20'; + kafkaPerson.sikkerhetstiltak[0].kontaktPersonId = 'Z000000'; + kafkaPerson.sikkerhetstiltak[0].kontaktPersonEnhet = '0000'; + + kafkaPerson.statsborgerskap.add('NOR'); + + kafkaPerson.sivilstand.add(new PDL_Sivilstand()); + kafkaPerson.sivilstand[0].type = PDL_Sivilstandstype.GIFT; + kafkaPerson.sivilstand[0].gyldigFraOgMed = Date.newInstance(2001, 6, 20); + kafkaPerson.sivilstand[0].relatertVedSivilstand = '12345678910'; + + kafkaPerson.kjoenn.add('MANN'); + + kafkaPerson.doedsfall.add(new KafkaPerson2.Doedsfall()); + kafkaPerson.doedsfall[0].doedsdato = '2019-01-29'; + kafkaPerson.doedsfall[0].master = 'FREG'; + + kafkaPerson.telefonnummer.add(new KafkaPerson2.Telefonnummer()); + kafkaPerson.telefonnummer[0].landskode = '+46'; + kafkaPerson.telefonnummer[0].nummer = '123456789'; + kafkaPerson.telefonnummer[0].prioritet = '2'; + kafkaPerson.telefonnummer.add(new KafkaPerson2.Telefonnummer()); + kafkaPerson.telefonnummer[1].landskode = '+47'; + kafkaPerson.telefonnummer[1].nummer = '987654321'; + kafkaPerson.telefonnummer[1].prioritet = '1'; + + kafkaPerson.utflyttingFraNorge.add(new PDL_UtflyttingFraNorge()); + kafkaPerson.utflyttingFraNorge[0].tilflyttingsland = 'IND'; + kafkaPerson.utflyttingFraNorge[0].tilflyttingsstedIUtlandet = 'Delhi'; + + kafkaPerson.talesspraaktolk = new List(); + kafkaPerson.talesspraaktolk.add('NO'); + + kafkaPerson.fullmakt = new List(); + kafkaPerson.fullmakt.add(new PersonJSONFieldObjects.Fullmakt()); + kafkaPerson.fullmakt[0].motpartsRolle = 'Fullmektig'; + kafkaPerson.fullmakt[0].motpartsPersonident = '12345678910'; + kafkaPerson.fullmakt[0].omraader = new List{ 'DAG' }; + kafkaPerson.fullmakt[0].gyldigFraOgMed = '2020-02-14'; + kafkaPerson.fullmakt[0].gyldigTilOgMed = '2020-02-28'; + + kafkaPerson.vergemaalEllerFremtidsfullmakt = new List(); + kafkaPerson.vergemaalEllerFremtidsfullmakt.add(new PersonJSONFieldObjects.VergemaalEllerFremtidsfullmakt()); + kafkaPerson.vergemaalEllerFremtidsfullmakt[0].type = 'stadfestetFremtidsfullmakt'; + kafkaPerson.vergemaalEllerFremtidsfullmakt[0].embete = 'Statsforvalter'; + kafkaPerson.vergemaalEllerFremtidsfullmakt[0].navn = null; + kafkaPerson.vergemaalEllerFremtidsfullmakt[0].motpartsPersonident = '12345678910'; + kafkaPerson.vergemaalEllerFremtidsfullmakt[0].omfang = 'Personlige og/eller økonomiske interesser'; + kafkaPerson.vergemaalEllerFremtidsfullmakt[0].omfangetErInnenPersonligOmraade = true; + + KafkaMessage__c message = createKafkaMessageHelper(kafkaPerson, '11223344556', false); + + Test.startTest(); + insert message; + AsyncRequestSchedulable.enqueueAsyncJobs(); + Test.stopTest(); + + isKafkaMessageProcessed( + [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message.Id LIMIT 1] + ); + + Person__c person = getPersonAccountByActorIdent().get('11223344556'); + + System.assertEquals('11223344556', person.INT_actorId__c, 'Expected AKTØR ID to be set'); + System.assertEquals('12345678901', person.INT_fnr__c, 'Expected FNR to be set'); + System.assertEquals(null, person.INT_npid__c, 'Expected NPID to be null'); + System.assertEquals(null, person.INT_dnr__c, 'Expect DNR to be null'); + System.assertEquals('12345678901', person.Name, 'Expected NAME to be same as FNR'); + + System.assertEquals('2020-02-25', person.INT_DateOfBirth__c, 'Expected '); + + System.assertEquals('TEST', person.INT_FirstName__c, 'Expected '); + System.assertEquals('T.', person.INT_MiddleName__c, 'Expected '); + System.assertEquals('TESTESEN', person.INT_LastName__c, 'Expected '); + + System.assertEquals('Bosatt', person.INT_LegalStatus__c, 'Expected '); + + System.assertNotEquals(null, person.INT_MovedFromCountry__c, 'Expected '); + System.assertEquals('Delhi', person.INT_MovedFromPlace__c, 'Expected '); + + System.assertEquals('UGRADERT', person.INT_Confidential__c, 'Expected '); + + System.assert(String.isNotBlank(person.INT_SecurityMeasures__c), 'Expected '); + + System.assertEquals('Norge', person.INT_Citizenships__c, 'Expected '); + + System.assertEquals('GIFT', person.INT_MaritalStatus__c, 'Expected '); + System.assertEquals(Date.newInstance(2001, 6, 20), person.INT_MaritalStatusDate__c, 'Expected '); + System.assertEquals('12345678910', person.INT_MaritalRelation__c, 'Expected '); + + System.assertEquals('Mann', person.INT_Sex__c, 'Expected '); + + System.assertEquals(Date.newInstance(2019, 1, 29), person.INT_DateOfDeath__c, 'Expected '); + System.assertEquals(true, person.INT_IsDeceased__c, 'Expected '); + + System.assertEquals('+47987654321', person.INT_Phone1__c, 'Expected '); + System.assertEquals('+46123456789', person.INT_Phone2__c, 'Expected '); + + System.assertNotEquals(null, person.INT_MovedToCountry__c, 'Expected '); + System.assertEquals('Delhi', person.INT_MovedToPlace__c, 'Expected '); + + System.assertEquals('NO', person.INT_SpokenLanguageIntepreter__c, 'Expected '); + + System.assert(String.isNotBlank(person.INT_PowerOfAttorney__c), 'Expected '); + System.assert(String.isNotBlank(person.INT_GuardianshipOrFuturePowerOfAttorney__c), 'Expected '); + } + + /*********************** + * TEST ADDRESS AND GT * + **********************/ + + @IsTest + static void setBostedVegadresse() { + Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); + KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); + kafkaPerson.bostedsadresse.vegadresse.add(new KafkaPerson2.Vegadresse()); + kafkaPerson.bostedsadresse.vegadresse[0].adressenavn = 'Testveien'; + kafkaPerson.bostedsadresse.vegadresse[0].husnummer = '1'; + kafkaPerson.bostedsadresse.vegadresse[0].husbokstav = 'A'; + kafkaPerson.bostedsadresse.vegadresse[0].postnummer = '0001'; + kafkaPerson.bostedsadresse.vegadresse[0].kommunenummer = '4321'; + kafkaPerson.bostedsadresse.vegadresse[0].bydelsnummer = '030110'; + kafkaPerson.bostedsadresse.vegadresse[0].koordinater = 'x=354424, y=6862099, z=0'; + + Test.startTest(); + KafkaPDLHandler2 handler = new KafkaPDLHandler2(); + handler.setAddress(person, kafkaPerson); + Test.stopTest(); + + System.assertEquals( + 'Testveien 1 A', + person.INT_ResidentialAddress__c, + 'Expected residential address to be set correctly' + ); + System.assertEquals('0001', person.INT_ResidentialZipCode__c, 'Expected residential zip code to be set'); + System.assertEquals( + '4321', + person.INT_AddressMunicipalityNumber__c, + 'Expected Address Municipality number to be set' + ); + System.assertEquals( + '030110', + person.INT_AddressDistrictNumber__c, + 'Expected Address District number to be set' + ); + System.assertEquals('x=354424, y=6862099, z=0', person.INT_Coordinates__c, 'Expected coordinates to be set'); + + System.assertEquals(null, person.INT_TemporaryAddress__c, 'Expected INT_TemporaryAddress__c to be null'); + System.assertEquals(null, person.INT_TemporaryZipCode__c, 'Expected INT_TemporaryZipCode__c to be null'); + System.assertEquals( + null, + person.INT_TemporaryMunicipalityNumber__c, + 'Expected INT_TemporaryMunicipalityNumber__c to be null' + ); + System.assertEquals( + null, + person.INT_TemporaryCoordinates__c, + 'Expected INT_TemporaryCoordinates__c to be null' + ); + System.assertEquals( + null, + person.INT_TemporaryCountryCode__c, + 'Expected INT_TemporaryCountryCode__c to be null' + ); + } + + @IsTest + static void setOppholdVegadresse() { + Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); + KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); + kafkaPerson.oppholdsadresse.vegadresse.add(new KafkaPerson2.Vegadresse()); + kafkaPerson.oppholdsadresse.vegadresse[0].adressenavn = 'Testveien'; + kafkaPerson.oppholdsadresse.vegadresse[0].husnummer = '1'; + kafkaPerson.oppholdsadresse.vegadresse[0].husbokstav = 'A'; + kafkaPerson.oppholdsadresse.vegadresse[0].postnummer = '0001'; + kafkaPerson.oppholdsadresse.vegadresse[0].kommunenummer = '4321'; + kafkaPerson.oppholdsadresse.vegadresse[0].bydelsnummer = '030110'; + kafkaPerson.oppholdsadresse.vegadresse[0].koordinater = 'x=354424, y=6862099, z=0'; + + Test.startTest(); + KafkaPDLHandler2 handler = new KafkaPDLHandler2(); + handler.setAddress(person, kafkaPerson); + Test.stopTest(); + + System.assertEquals(null, person.INT_ResidentialAddress__c, 'Expected INT_ResidentialAddress__c to be null'); + System.assertEquals(null, person.INT_ResidentialZipCode__c, 'Expected INT_ResidentialZipCode__c to be null'); + System.assertEquals( + null, + person.INT_AddressMunicipalityNumber__c, + 'Expected INT_AddressMunicipalityNumber__c to be null' + ); + System.assertEquals( + null, + person.INT_AddressDistrictNumber__c, + 'Expected INT_AddressDistrictNumber__c to be null' + ); + System.assertEquals(null, person.INT_Coordinates__c, 'Expected INT_Coordinates__c to be null'); + + System.assertEquals( + 'Testveien 1 A', + person.INT_TemporaryAddress__c, + 'Expected residential address to be set correctly' + ); + System.assertEquals('0001', person.INT_TemporaryZipCode__c, 'Expected residential zip code to be set'); + System.assertEquals( + '4321', + person.INT_TemporaryMunicipalityNumber__c, + 'Expected Address Municipality number to be set' + ); + System.assertEquals( + 'x=354424, y=6862099, z=0', + person.INT_TemporaryCoordinates__c, + 'Expected coordinates to be set' + ); + System.assertEquals( + null, + person.INT_TemporaryCountryCode__c, + 'Expected INT_TemporaryCountryCode__c to be null' + ); + } + @IsTest + static void setGTFromKommunenummer() { + Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); + KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); + kafkaPerson.kommunenummerFraGt = '0301'; + kafkaPerson.bydelsnummerFraGt = '030101'; + + Test.startTest(); + KafkaPDLHandler2 handler = new KafkaPDLHandler2(); + handler.setMunicipalityAndGT(person, kafkaPerson); + Test.stopTest(); + + System.assertEquals( + '0301', + person.INT_GTMunicipalityNumber__c, + 'Expected INT_GTMunicipalityNumber__c to be set' + ); + System.assertEquals('030101', person.INT_GTDistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + System.assertEquals('03', person.INT_RegionNumber__c, 'Expected INT_RegionNumber__c to be set'); + System.assertEquals('0301', person.INT_MunicipalityNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + System.assertEquals('030101', person.INT_DistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + } + + @IsTest + static void setGTFromKommunenummerNoDistrict() { + Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); + KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); + kafkaPerson.kommunenummerFraGt = '0301'; + + Test.startTest(); + KafkaPDLHandler2 handler = new KafkaPDLHandler2(); + handler.setMunicipalityAndGT(person, kafkaPerson); + Test.stopTest(); + + System.assertEquals( + '0301', + person.INT_GTMunicipalityNumber__c, + 'Expected INT_GTMunicipalityNumber__c to be set' + ); + System.assertEquals(null, person.INT_GTDistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + System.assertEquals('03', person.INT_RegionNumber__c, 'Expected INT_RegionNumber__c to be set'); + System.assertEquals('0301', person.INT_MunicipalityNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + System.assertEquals(null, person.INT_DistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + } + + @IsTest + static void setGTFromKommunenummerFromAddressOnly() { + Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); + KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); + kafkaPerson.bostedsadresse.vegadresse.add(new KafkaPerson2.Vegadresse()); + kafkaPerson.bostedsadresse.vegadresse[0].adressenavn = 'Testveien'; + kafkaPerson.bostedsadresse.vegadresse[0].adressenavn = '1'; + kafkaPerson.bostedsadresse.vegadresse[0].adressenavn = 'A'; + kafkaPerson.bostedsadresse.vegadresse[0].postnummer = '0001'; + kafkaPerson.bostedsadresse.vegadresse[0].kommunenummer = '4321'; + kafkaPerson.bostedsadresse.vegadresse[0].bydelsnummer = '030110'; + kafkaPerson.bostedsadresse.vegadresse[0].koordinater = 'x=354424, y=6862099, z=0'; + + Test.startTest(); + KafkaPDLHandler2 handler = new KafkaPDLHandler2(); + handler.setAddress(person, kafkaPerson); + handler.setMunicipalityAndGT(person, kafkaPerson); + Test.stopTest(); + + System.assertEquals(null, person.INT_GTMunicipalityNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + System.assertEquals(null, person.INT_GTDistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + System.assertEquals(null, person.INT_RegionNumber__c, 'Expected INT_RegionNumber__c to be set'); + System.assertEquals('4321', person.INT_MunicipalityNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + System.assertEquals('030110', person.INT_DistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + } + + /*********** + * HELPERS * + **********/ + private static void isKafkaMessageProcessed(KafkaMessage__c message) { + System.assertEquals( + KafkaMessageService.STATUS_PROCESSED, + message.CRM_Status__c, + 'Expected message to be processed but it is ' + + message.CRM_Status__c + + '. CRM_ErrorMessage__c: ' + + message.CRM_ErrorMessage__c + ); + } + + private static KafkaPerson2 createBaseKafkaPersonOld(String actorId) { + KafkaPerson2 kafkaPerson = createBaseKafkaPerson(actorId); + kafkaPerson.aktoerId = actorId; + kafkaPerson.folkeregisterId = new List(); + kafkaPerson.folkeregisteridentifikator = null; + kafkaPerson.identer = null; + return kafkaPerson; + } + + private static KafkaPerson2 createBaseKafkaPerson(String actorId) { + KafkaPerson2 kafkaPerson = new KafkaPerson2(); + kafkaPerson.identer = new List(); + kafkaPerson.folkeregisteridentifikator = new List(); + kafkaPerson.foedselsdato = new List(); + kafkaPerson.folkeregisterpersonstatus = new List(); + kafkaPerson.navn = new List(); + kafkaPerson.bostedsadresse = new KafkaPerson2.Adresser(); + kafkaPerson.bostedsadresse.vegadresse = new List(); + kafkaPerson.bostedsadresse.matrikkeladresse = new List(); + kafkaPerson.bostedsadresse.utenlandskAdresse = new List(); + kafkaPerson.bostedsadresse.ukjentBosted = new List(); + kafkaPerson.oppholdsadresse = new KafkaPerson2.Adresser(); + kafkaPerson.oppholdsadresse.vegadresse = new List(); + kafkaPerson.oppholdsadresse.matrikkeladresse = new List(); + kafkaPerson.oppholdsadresse.utenlandskAdresse = new List(); + kafkaPerson.oppholdsadresse.ukjentBosted = new List(); + kafkaPerson.innflyttingTilNorge = new List(); + kafkaPerson.utflyttingFraNorge = new List(); + kafkaPerson.adressebeskyttelse = new List(); + kafkaPerson.kommunenummerFraGt = ''; + kafkaPerson.bydelsnummerFraGt = ''; + kafkaPerson.sivilstand = new List(); + kafkaPerson.statsborgerskap = new List(); + kafkaPerson.kjoenn = new List(); + kafkaPerson.doedsfall = new List(); + kafkaPerson.telefonnummer = new List(); + + //Default values + //Ident + kafkaPerson.identer.add(new PDL_IdentInformasjon()); + kafkaPerson.identer[0].gruppe = PDL_IdentGruppe.AKTORID; + kafkaPerson.identer[0].historisk = false; + kafkaPerson.identer[0].ident = actorId; + //Person status + kafkaPerson.folkeregisterpersonstatus.add('bosatt'); + //Navn + kafkaPerson.navn.add(new PDL_Navn()); + kafkaPerson.navn[0].etternavn = 'TESTESEN'; + kafkaPerson.adressebeskyttelse.add('UGRADERT'); + + return kafkaPerson; + } + + private static KafkaMessage__c createKafkaMessageHelper( + KafkaPerson2 kafkaPerson, + String aktorId, + Boolean tombstone + ) { + KafkaMessage__c kafkaMessage = new KafkaMessage__c( + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf(JSON.serialize(kafkaPerson))), + CRM_Key__c = EncodingUtil.base64Encode( + Blob.valueOf('{"aktoer_id":"' + aktorId + '","tombstone":' + tombstone + '}') + ), + CRM_Topic__c = 'teamnks.nks-sf-pdl-v3' + ); + + return kafkaMessage; + } + + private static Map getPersonAccountByActorIdent() { + Map personByActorIdent = new Map(); + for (Person__c person : [ + SELECT + Id, + Name, + INT_ActorId__c, + INT_AddressDistrictNumber__c, + INT_AddressMunicipalityNumber__c, + INT_Citizenships__c, + INT_Confidential__c, + INT_Coordinates__c, + INT_DateOfBirth__c, + INT_DateOfDeath__c, + INT_DistrictNumber__c, + INT_dnr__c, + INT_FamilyRelations__c, + INT_fnr__c, + INT_FirstName__c, + INT_GTDistrictNumber__c, + INT_GTMunicipalityNumber__c, + INT_GuardianshipOrFuturePowerOfAttorney__c, + INT_IsDeceased__c, + INT_IsNavEmployee__c, + INT_LastName__c, + INT_LastUpdatedFromPDL__c, + INT_LastUpdatedFromKRR__c, + INT_LegalStatus__c, + INT_MaritalRelation__c, + INT_MaritalStatus__c, + INT_MaritalStatusDate__c, + INT_MiddleName__c, + INT_MovedFromCountry__c, + INT_MovedFromPlace__c, + INT_MovedToCountry__c, + INT_MovedToPlace__c, + INT_MunicipalityNumber__c, + INT_npid__c, + INT_Phone1__c, + INT_Phone2__c, + INT_PowerOfAttorney__c, + INT_RegionNumber__c, + INT_ResidentialAddress__c, + INT_ResidentialZipCode__c, + INT_SecurityMeasures__c, + INT_Sex__c, + INT_SpokenLanguageIntepreter__c, + INT_TemporaryAddress__c, + INT_TemporaryCountryCode__c, + INT_TemporaryMunicipalityNumber__c, + INT_TemporaryZipCode__c, + INT_TemporaryCoordinates__c + FROM Person__c + ]) { + personByActorIdent.put(person.INT_ActorId__c, person); + } + return personByActorIdent; + } +} diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls-meta.xml b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-handler/classes/KafkaPersonGt.cls b/force-app/pdl-handler/classes/KafkaPersonGt.cls new file mode 100644 index 00000000..224d3c76 --- /dev/null +++ b/force-app/pdl-handler/classes/KafkaPersonGt.cls @@ -0,0 +1,11 @@ +/** + * Person with only GeografiskTilknytning + */ +public with sharing class KafkaPersonGt { + public List identer; + public PdlGeografiskTilknytning geografiskTilknytning; + + public static KafkaPersonGt parse(String json) { + return (KafkaPersonGt) System.JSON.deserialize(json, KafkaPersonGt.class); + } +} diff --git a/force-app/pdl-handler/classes/KafkaPersonGt.cls-meta.xml b/force-app/pdl-handler/classes/KafkaPersonGt.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-handler/classes/KafkaPersonGt.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlGeografiskTilknytning.md-meta.xml b/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlGeografiskTilknytning.md-meta.xml new file mode 100644 index 00000000..9edb12ba --- /dev/null +++ b/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlGeografiskTilknytning.md-meta.xml @@ -0,0 +1,29 @@ + + + + false + + ApexClass__c + KafkaPdlGtHandler + + + Description__c + + + + Priority__c + 20.0 + + + Topic__c + pdl.geografisktilknytning-v1 + + + ApexJobType__c + Batch Apex + + From 292986085189619012a075c68568bfac24729ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 15 Jan 2024 00:55:52 +0100 Subject: [PATCH 004/159] write failing test testCreatePersonFromPersonDo... --- .../classes/KafkaPdlPersondokumentHandler.cls | 6 +- .../KafkaPdlPersondokumentHandlerTest.cls | 335 ++++++++++++++++++ 2 files changed, 338 insertions(+), 3 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index f7ffaa25..c52d99d7 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -553,8 +553,8 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess // prettier-ignore private void validateListSizes(KafkaPerson2 kafkaPerson) { List objectsFailingValidation = new List(); - - + + if(kafkaPerson.identer == null) { if (kafkaPerson.folkeregisterId.size() == 0) { throw new pdlMissingEntryException('No folkeregisterId found'); } if (kafkaPerson.folkeregisterpersonstatus.size() == 0) { throw new pdlMissingEntryException('No folkeregisterpersonstatus found'); } @@ -574,7 +574,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess if (kafkaPerson.oppholdsadresse.matrikkeladresse.size() > 1) { objectsFailingValidation.add('oppholdsadresse.matrikkeladresse'); } if (kafkaPerson.oppholdsadresse.utenlandskAdresse.size() > 1) { objectsFailingValidation.add('oppholdsadresse.utenlandskAdresse'); } if (kafkaPerson.oppholdsadresse.ukjentBosted.size() > 1) { objectsFailingValidation.add('oppholdsadresse.ukjentBosted'); } - + if (objectsFailingValidation.size() > 0) { throw new pdlListContainsTooManyEntriesException( 'Multiple objects received for ' + diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index b01dee9b..6a0f8db6 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -22,6 +22,341 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { insert commonCodes; } + @isTest + static void testCreatePersonFromPersonDokument() { + List kafkaMessages = new List(); + kafkaMessages.add( + new KafkaMessage__c( + CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Key__c = '2594819806563', + //{ + // "hentPerson": { + // "adressebeskyttelse": [], + // "bostedsadresse": [ + // { + // "angittFlyttedato": "1972-07-01", + // "gyldigFraOgMed": "1972-07-01T00:00:00", + // "gyldigTilOgMed": null, + // "coAdressenavn": null, + // "vegadresse": { + // "matrikkelId": 138391329, + // "husnummer": "11", + // "husbokstav": null, + // "bruksenhetsnummer": null, + // "adressenavn": "Marihandstien", + // "kommunenummer": "1806", + // "tilleggsnavn": null, + // "postnummer": "8515", + // "bydelsnummer": null, + // "koordinater": { + // "x": 599891.371546, + // "y": 7592866.900335, + // "z": null + // } + // }, + // "matrikkeladresse": null, + // "ukjentBosted": null, + // "utenlandskAdresse": null, + // "folkeregistermetadata": { + // "ajourholdstidspunkt": "2022-01-14T15:41:37.045", + // "gyldighetstidspunkt": "1972-07-01T00:00:00", + // "opphoerstidspunkt": null, + // "kilde": "Dolly", + // "aarsak": null, + // "sekvens": null + // }, + // "metadata": { + // "opplysningsId": "e52735a2-be2f-4b2a-b578-dec2f032e8dd", + // "master": "FREG", + // "endringer": [ + // { + // "type": "OPPRETT", + // "registrert": "2022-01-14T15:41:37.045", + // "registrertAv": "Folkeregisteret", + // "systemkilde": "FREG", + // "kilde": "Dolly" + // } + // ], + // "historisk": false + // } + // } + // ], + // "doedsfall": [], + // "foedsel": [ + // { + // "foedselsaar": 1972, + // "foedselsdato": "1972-07-01", + // "foedeland": "BEL", + // "foedested": "Fødested i/på BELGIA", + // "foedekommune": null, + // "metadata": { + // "opplysningsId": "fadd61cf-0da2-4df1-9492-a5fb1532f50f", + // "master": "FREG", + // "endringer": [ + // { + // "type": "OPPRETT", + // "registrert": "2022-01-14T15:41:35.412", + // "registrertAv": "Folkeregisteret", + // "systemkilde": "FREG", + // "kilde": "Dolly" + // } + // ], + // "historisk": false + // }, + // "folkeregistermetadata": { + // "ajourholdstidspunkt": "2022-01-14T15:41:35.412", + // "gyldighetstidspunkt": "2022-01-14T15:41:35.412", + // "opphoerstidspunkt": null, + // "kilde": "Dolly", + // "aarsak": null, + // "sekvens": null + // } + // } + // ], + // "folkeregisteridentifikator": [ + // { + // "identifikasjonsnummer": "01077211027", + // "type": "FNR", + // "status": "I_BRUK", + // "folkeregistermetadata": { + // "ajourholdstidspunkt": "2022-01-14T15:41:34.945", + // "gyldighetstidspunkt": "2022-01-14T15:41:34.945", + // "opphoerstidspunkt": null, + // "kilde": "srvdolly", + // "aarsak": null, + // "sekvens": null + // }, + // "metadata": { + // "opplysningsId": "4ed45e87-e02b-4aa0-8601-689bbd58f20f", + // "master": "FREG", + // "endringer": [ + // { + // "type": "OPPRETT", + // "registrert": "2022-01-14T15:41:35.058", + // "registrertAv": "Folkeregisteret", + // "systemkilde": "FREG", + // "kilde": "srvdolly" + // } + // ], + // "historisk": false + // } + // } + // ], + // "folkeregisterpersonstatus": [ + // { + // "status": "bosatt", + // "forenkletStatus": "bosattEtterFolkeregisterloven", + // "folkeregistermetadata": { + // "ajourholdstidspunkt": "2022-01-14T15:41:37.899", + // "gyldighetstidspunkt": "2022-01-14T15:41:37.899", + // "opphoerstidspunkt": null, + // "kilde": "Dolly", + // "aarsak": null, + // "sekvens": null + // }, + // "metadata": { + // "opplysningsId": "37065f2d-5f9e-4046-a6d3-9f6856961cd6", + // "master": "FREG", + // "endringer": [ + // { + // "type": "OPPRETT", + // "registrert": "2022-01-14T15:41:37.899", + // "registrertAv": "Folkeregisteret", + // "systemkilde": "FREG", + // "kilde": "Dolly" + // } + // ], + // "historisk": false + // } + // } + // ], + // "forelderBarnRelasjon": [], + // "fullmakt": [], + // "kjoenn": [ + // { + // "kjoenn": "KVINNE", + // "folkeregistermetadata": { + // "ajourholdstidspunkt": "2022-01-14T15:41:36.62", + // "gyldighetstidspunkt": "2022-01-14T15:41:36.62", + // "opphoerstidspunkt": null, + // "kilde": "Dolly", + // "aarsak": null, + // "sekvens": null + // }, + // "metadata": { + // "opplysningsId": "0847b543-0847-4494-9fca-857a1ca51a73", + // "master": "FREG", + // "endringer": [ + // { + // "type": "OPPRETT", + // "registrert": "2022-01-14T15:41:36.62", + // "registrertAv": "Folkeregisteret", + // "systemkilde": "FREG", + // "kilde": "Dolly" + // } + // ], + // "historisk": false + // } + // } + // ], + // "navn": [ + // { + // "fornavn": "ARTIG", + // "mellomnavn": null, + // "etternavn": "SNERK", + // "forkortetNavn": "SNERK ARTIG", + // "originaltNavn": null, + // "gyldigFraOgMed": "2022-01-14", + // "folkeregistermetadata": { + // "ajourholdstidspunkt": "2022-01-14T15:41:36.237", + // "gyldighetstidspunkt": "2022-01-14T15:41:36.237", + // "opphoerstidspunkt": null, + // "kilde": "Dolly", + // "aarsak": null, + // "sekvens": null + // }, + // "metadata": { + // "opplysningsId": "44fbf7a6-6885-48ad-a303-e9d90fa4567f", + // "master": "FREG", + // "endringer": [ + // { + // "type": "OPPRETT", + // "registrert": "2022-01-14T15:41:36.237", + // "registrertAv": "Folkeregisteret", + // "systemkilde": "FREG", + // "kilde": "Dolly" + // } + // ], + // "historisk": false + // } + // } + // ], + // "oppholdsadresse": [], + // "sikkerhetstiltak": [], + // "sivilstand": [ + // { + // "type": "UGIFT", + // "gyldigFraOgMed": null, + // "relatertVedSivilstand": null, + // "bekreftelsesdato": null, + // "folkeregistermetadata": { + // "ajourholdstidspunkt": "2022-01-14T15:41:38.684", + // "gyldighetstidspunkt": "2022-01-14T15:41:38.684", + // "opphoerstidspunkt": null, + // "kilde": "Dolly", + // "aarsak": null, + // "sekvens": null + // }, + // "metadata": { + // "opplysningsId": "2d7f6623-3ba4-44d3-8e04-efced8cd77e3", + // "master": "FREG", + // "endringer": [ + // { + // "type": "OPPRETT", + // "registrert": "2022-01-14T15:41:38.684", + // "registrertAv": "Folkeregisteret", + // "systemkilde": "FREG", + // "kilde": "Dolly" + // } + // ], + // "historisk": false + // } + // } + // ], + // "statsborgerskap": [ + // { + // "land": "NOR", + // "bekreftelsesdato": null, + // "gyldigFraOgMed": "1972-07-01", + // "gyldigTilOgMed": null, + // "folkeregistermetadata": { + // "ajourholdstidspunkt": "2022-01-14T15:41:38.327", + // "gyldighetstidspunkt": "1972-07-01T00:00:00", + // "opphoerstidspunkt": null, + // "kilde": "Dolly", + // "aarsak": null, + // "sekvens": null + // }, + // "metadata": { + // "opplysningsId": "672b293a-b18e-4cd1-9a16-d4a03eb8581d", + // "master": "FREG", + // "endringer": [ + // { + // "type": "OPPRETT", + // "registrert": "2022-01-14T15:41:38.326", + // "registrertAv": "Folkeregisteret", + // "systemkilde": "FREG", + // "kilde": "Dolly" + // } + // ], + // "historisk": false + // } + // } + // ], + // "tilrettelagtKommunikasjon": [], + // "telefonnummer": [], + // "innflyttingTilNorge": [ + // { + // "fraflyttingsland": "BEL", + // "fraflyttingsstedIUtlandet": null, + // "folkeregistermetadata": { + // "ajourholdstidspunkt": "2022-01-14T15:41:37.532", + // "gyldighetstidspunkt": "1972-07-01T00:00:00", + // "opphoerstidspunkt": null, + // "kilde": "Dolly", + // "aarsak": null, + // "sekvens": null + // }, + // "metadata": { + // "opplysningsId": "5345af76-ac03-4461-9d5c-f17c42ea8a32", + // "master": "FREG", + // "endringer": [ + // { + // "type": "OPPRETT", + // "registrert": "2022-01-14T15:41:37.532", + // "registrertAv": "Folkeregisteret", + // "systemkilde": "FREG", + // "kilde": "Dolly" + // } + // ], + // "historisk": false + // } + // } + // ], + // "utflyttingFraNorge": [], + // "vergemaalEllerFremtidsfullmakt": [] + // }, + // "hentIdenter": { + // "identer": [ + // { + // "ident": "01077211027", + // "historisk": false, + // "gruppe": "FOLKEREGISTERIDENT", + // "metadata": null, + // "folkeregistermetadata": null + // }, + // { + // "ident": "2594819806563", + // "historisk": false, + // "gruppe": "AKTORID", + // "metadata": null, + // "folkeregistermetadata": null + // } + // ] + // } + //} + CRM_Value__c = 'eyJoZW50UGVyc29uIjp7ImFkcmVzc2ViZXNreXR0ZWxzZSI6W10sImJvc3RlZHNhZHJlc3NlIjpbeyJhbmdpdHRGbHl0dGVkYXRvIjoiMTk3Mi0wNy0wMSIsImd5bGRpZ0ZyYU9nTWVkIjoiMTk3Mi0wNy0wMVQwMDowMDowMCIsImd5bGRpZ1RpbE9nTWVkIjpudWxsLCJjb0FkcmVzc2VuYXZuIjpudWxsLCJ2ZWdhZHJlc3NlIjp7Im1hdHJpa2tlbElkIjoxMzgzOTEzMjksImh1c251bW1lciI6IjExIiwiaHVzYm9rc3RhdiI6bnVsbCwiYnJ1a3NlbmhldHNudW1tZXIiOm51bGwsImFkcmVzc2VuYXZuIjoiTWFyaWhhbmRzdGllbiIsImtvbW11bmVudW1tZXIiOiIxODA2IiwidGlsbGVnZ3NuYXZuIjpudWxsLCJwb3N0bnVtbWVyIjoiODUxNSIsImJ5ZGVsc251bW1lciI6bnVsbCwia29vcmRpbmF0ZXIiOnsieCI6NTk5ODkxLjM3MTU0NiwieSI6NzU5Mjg2Ni45MDAzMzUsInoiOm51bGx9fSwibWF0cmlra2VsYWRyZXNzZSI6bnVsbCwidWtqZW50Qm9zdGVkIjpudWxsLCJ1dGVubGFuZHNrQWRyZXNzZSI6bnVsbCwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjp7ImFqb3VyaG9sZHN0aWRzcHVua3QiOiIyMDIyLTAxLTE0VDE1OjQxOjM3LjA0NSIsImd5bGRpZ2hldHN0aWRzcHVua3QiOiIxOTcyLTA3LTAxVDAwOjAwOjAwIiwib3BwaG9lcnN0aWRzcHVua3QiOm51bGwsImtpbGRlIjoiRG9sbHkiLCJhYXJzYWsiOm51bGwsInNla3ZlbnMiOm51bGx9LCJtZXRhZGF0YSI6eyJvcHBseXNuaW5nc0lkIjoiZTUyNzM1YTItYmUyZi00YjJhLWI1NzgtZGVjMmYwMzJlOGRkIiwibWFzdGVyIjoiRlJFRyIsImVuZHJpbmdlciI6W3sidHlwZSI6Ik9QUFJFVFQiLCJyZWdpc3RyZXJ0IjoiMjAyMi0wMS0xNFQxNTo0MTozNy4wNDUiLCJyZWdpc3RyZXJ0QXYiOiJGb2xrZXJlZ2lzdGVyZXQiLCJzeXN0ZW1raWxkZSI6IkZSRUciLCJraWxkZSI6IkRvbGx5In1dLCJoaXN0b3Jpc2siOmZhbHNlfX1dLCJkb2Vkc2ZhbGwiOltdLCJmb2Vkc2VsIjpbeyJmb2Vkc2Vsc2FhciI6MTk3MiwiZm9lZHNlbHNkYXRvIjoiMTk3Mi0wNy0wMSIsImZvZWRlbGFuZCI6IkJFTCIsImZvZWRlc3RlZCI6IkbDuGRlc3RlZCBpL3DDpSBCRUxHSUEiLCJmb2VkZWtvbW11bmUiOm51bGwsIm1ldGFkYXRhIjp7Im9wcGx5c25pbmdzSWQiOiJmYWRkNjFjZi0wZGEyLTRkZjEtOTQ5Mi1hNWZiMTUzMmY1MGYiLCJtYXN0ZXIiOiJGUkVHIiwiZW5kcmluZ2VyIjpbeyJ0eXBlIjoiT1BQUkVUVCIsInJlZ2lzdHJlcnQiOiIyMDIyLTAxLTE0VDE1OjQxOjM1LjQxMiIsInJlZ2lzdHJlcnRBdiI6IkZvbGtlcmVnaXN0ZXJldCIsInN5c3RlbWtpbGRlIjoiRlJFRyIsImtpbGRlIjoiRG9sbHkifV0sImhpc3RvcmlzayI6ZmFsc2V9LCJmb2xrZXJlZ2lzdGVybWV0YWRhdGEiOnsiYWpvdXJob2xkc3RpZHNwdW5rdCI6IjIwMjItMDEtMTRUMTU6NDE6MzUuNDEyIiwiZ3lsZGlnaGV0c3RpZHNwdW5rdCI6IjIwMjItMDEtMTRUMTU6NDE6MzUuNDEyIiwib3BwaG9lcnN0aWRzcHVua3QiOm51bGwsImtpbGRlIjoiRG9sbHkiLCJhYXJzYWsiOm51bGwsInNla3ZlbnMiOm51bGx9fV0sImZvbGtlcmVnaXN0ZXJpZGVudGlmaWthdG9yIjpbeyJpZGVudGlmaWthc2pvbnNudW1tZXIiOiIwMTA3NzIxMTAyNyIsInR5cGUiOiJGTlIiLCJzdGF0dXMiOiJJX0JSVUsiLCJmb2xrZXJlZ2lzdGVybWV0YWRhdGEiOnsiYWpvdXJob2xkc3RpZHNwdW5rdCI6IjIwMjItMDEtMTRUMTU6NDE6MzQuOTQ1IiwiZ3lsZGlnaGV0c3RpZHNwdW5rdCI6IjIwMjItMDEtMTRUMTU6NDE6MzQuOTQ1Iiwib3BwaG9lcnN0aWRzcHVua3QiOm51bGwsImtpbGRlIjoic3J2ZG9sbHkiLCJhYXJzYWsiOm51bGwsInNla3ZlbnMiOm51bGx9LCJtZXRhZGF0YSI6eyJvcHBseXNuaW5nc0lkIjoiNGVkNDVlODctZTAyYi00YWEwLTg2MDEtNjg5YmJkNThmMjBmIiwibWFzdGVyIjoiRlJFRyIsImVuZHJpbmdlciI6W3sidHlwZSI6Ik9QUFJFVFQiLCJyZWdpc3RyZXJ0IjoiMjAyMi0wMS0xNFQxNTo0MTozNS4wNTgiLCJyZWdpc3RyZXJ0QXYiOiJGb2xrZXJlZ2lzdGVyZXQiLCJzeXN0ZW1raWxkZSI6IkZSRUciLCJraWxkZSI6InNydmRvbGx5In1dLCJoaXN0b3Jpc2siOmZhbHNlfX1dLCJmb2xrZXJlZ2lzdGVycGVyc29uc3RhdHVzIjpbeyJzdGF0dXMiOiJib3NhdHQiLCJmb3JlbmtsZXRTdGF0dXMiOiJib3NhdHRFdHRlckZvbGtlcmVnaXN0ZXJsb3ZlbiIsImZvbGtlcmVnaXN0ZXJtZXRhZGF0YSI6eyJham91cmhvbGRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTozNy44OTkiLCJneWxkaWdoZXRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTozNy44OTkiLCJvcHBob2Vyc3RpZHNwdW5rdCI6bnVsbCwia2lsZGUiOiJEb2xseSIsImFhcnNhayI6bnVsbCwic2VrdmVucyI6bnVsbH0sIm1ldGFkYXRhIjp7Im9wcGx5c25pbmdzSWQiOiIzNzA2NWYyZC01ZjllLTQwNDYtYTZkMy05ZjY4NTY5NjFjZDYiLCJtYXN0ZXIiOiJGUkVHIiwiZW5kcmluZ2VyIjpbeyJ0eXBlIjoiT1BQUkVUVCIsInJlZ2lzdHJlcnQiOiIyMDIyLTAxLTE0VDE1OjQxOjM3Ljg5OSIsInJlZ2lzdHJlcnRBdiI6IkZvbGtlcmVnaXN0ZXJldCIsInN5c3RlbWtpbGRlIjoiRlJFRyIsImtpbGRlIjoiRG9sbHkifV0sImhpc3RvcmlzayI6ZmFsc2V9fV0sImZvcmVsZGVyQmFyblJlbGFzam9uIjpbXSwiZnVsbG1ha3QiOltdLCJram9lbm4iOlt7Imtqb2VubiI6IktWSU5ORSIsImZvbGtlcmVnaXN0ZXJtZXRhZGF0YSI6eyJham91cmhvbGRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTozNi42MiIsImd5bGRpZ2hldHN0aWRzcHVua3QiOiIyMDIyLTAxLTE0VDE1OjQxOjM2LjYyIiwib3BwaG9lcnN0aWRzcHVua3QiOm51bGwsImtpbGRlIjoiRG9sbHkiLCJhYXJzYWsiOm51bGwsInNla3ZlbnMiOm51bGx9LCJtZXRhZGF0YSI6eyJvcHBseXNuaW5nc0lkIjoiMDg0N2I1NDMtMDg0Ny00NDk0LTlmY2EtODU3YTFjYTUxYTczIiwibWFzdGVyIjoiRlJFRyIsImVuZHJpbmdlciI6W3sidHlwZSI6Ik9QUFJFVFQiLCJyZWdpc3RyZXJ0IjoiMjAyMi0wMS0xNFQxNTo0MTozNi42MiIsInJlZ2lzdHJlcnRBdiI6IkZvbGtlcmVnaXN0ZXJldCIsInN5c3RlbWtpbGRlIjoiRlJFRyIsImtpbGRlIjoiRG9sbHkifV0sImhpc3RvcmlzayI6ZmFsc2V9fV0sIm5hdm4iOlt7ImZvcm5hdm4iOiJBUlRJRyIsIm1lbGxvbW5hdm4iOm51bGwsImV0dGVybmF2biI6IlNORVJLIiwiZm9ya29ydGV0TmF2biI6IlNORVJLIEFSVElHIiwib3JpZ2luYWx0TmF2biI6bnVsbCwiZ3lsZGlnRnJhT2dNZWQiOiIyMDIyLTAxLTE0IiwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjp7ImFqb3VyaG9sZHN0aWRzcHVua3QiOiIyMDIyLTAxLTE0VDE1OjQxOjM2LjIzNyIsImd5bGRpZ2hldHN0aWRzcHVua3QiOiIyMDIyLTAxLTE0VDE1OjQxOjM2LjIzNyIsIm9wcGhvZXJzdGlkc3B1bmt0IjpudWxsLCJraWxkZSI6IkRvbGx5IiwiYWFyc2FrIjpudWxsLCJzZWt2ZW5zIjpudWxsfSwibWV0YWRhdGEiOnsib3BwbHlzbmluZ3NJZCI6IjQ0ZmJmN2E2LTY4ODUtNDhhZC1hMzAzLWU5ZDkwZmE0NTY3ZiIsIm1hc3RlciI6IkZSRUciLCJlbmRyaW5nZXIiOlt7InR5cGUiOiJPUFBSRVRUIiwicmVnaXN0cmVydCI6IjIwMjItMDEtMTRUMTU6NDE6MzYuMjM3IiwicmVnaXN0cmVydEF2IjoiRm9sa2VyZWdpc3RlcmV0Iiwic3lzdGVta2lsZGUiOiJGUkVHIiwia2lsZGUiOiJEb2xseSJ9XSwiaGlzdG9yaXNrIjpmYWxzZX19XSwib3BwaG9sZHNhZHJlc3NlIjpbXSwic2lra2VyaGV0c3RpbHRhayI6W10sInNpdmlsc3RhbmQiOlt7InR5cGUiOiJVR0lGVCIsImd5bGRpZ0ZyYU9nTWVkIjpudWxsLCJyZWxhdGVydFZlZFNpdmlsc3RhbmQiOm51bGwsImJla3JlZnRlbHNlc2RhdG8iOm51bGwsImZvbGtlcmVnaXN0ZXJtZXRhZGF0YSI6eyJham91cmhvbGRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTozOC42ODQiLCJneWxkaWdoZXRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTozOC42ODQiLCJvcHBob2Vyc3RpZHNwdW5rdCI6bnVsbCwia2lsZGUiOiJEb2xseSIsImFhcnNhayI6bnVsbCwic2VrdmVucyI6bnVsbH0sIm1ldGFkYXRhIjp7Im9wcGx5c25pbmdzSWQiOiIyZDdmNjYyMy0zYmE0LTQ0ZDMtOGUwNC1lZmNlZDhjZDc3ZTMiLCJtYXN0ZXIiOiJGUkVHIiwiZW5kcmluZ2VyIjpbeyJ0eXBlIjoiT1BQUkVUVCIsInJlZ2lzdHJlcnQiOiIyMDIyLTAxLTE0VDE1OjQxOjM4LjY4NCIsInJlZ2lzdHJlcnRBdiI6IkZvbGtlcmVnaXN0ZXJldCIsInN5c3RlbWtpbGRlIjoiRlJFRyIsImtpbGRlIjoiRG9sbHkifV0sImhpc3RvcmlzayI6ZmFsc2V9fV0sInN0YXRzYm9yZ2Vyc2thcCI6W3sibGFuZCI6Ik5PUiIsImJla3JlZnRlbHNlc2RhdG8iOm51bGwsImd5bGRpZ0ZyYU9nTWVkIjoiMTk3Mi0wNy0wMSIsImd5bGRpZ1RpbE9nTWVkIjpudWxsLCJmb2xrZXJlZ2lzdGVybWV0YWRhdGEiOnsiYWpvdXJob2xkc3RpZHNwdW5rdCI6IjIwMjItMDEtMTRUMTU6NDE6MzguMzI3IiwiZ3lsZGlnaGV0c3RpZHNwdW5rdCI6IjE5NzItMDctMDFUMDA6MDA6MDAiLCJvcHBob2Vyc3RpZHNwdW5rdCI6bnVsbCwia2lsZGUiOiJEb2xseSIsImFhcnNhayI6bnVsbCwic2VrdmVucyI6bnVsbH0sIm1ldGFkYXRhIjp7Im9wcGx5c25pbmdzSWQiOiI2NzJiMjkzYS1iMThlLTRjZDEtOWExNi1kNGEwM2ViODU4MWQiLCJtYXN0ZXIiOiJGUkVHIiwiZW5kcmluZ2VyIjpbeyJ0eXBlIjoiT1BQUkVUVCIsInJlZ2lzdHJlcnQiOiIyMDIyLTAxLTE0VDE1OjQxOjM4LjMyNiIsInJlZ2lzdHJlcnRBdiI6IkZvbGtlcmVnaXN0ZXJldCIsInN5c3RlbWtpbGRlIjoiRlJFRyIsImtpbGRlIjoiRG9sbHkifV0sImhpc3RvcmlzayI6ZmFsc2V9fV0sInRpbHJldHRlbGFndEtvbW11bmlrYXNqb24iOltdLCJ0ZWxlZm9ubnVtbWVyIjpbXSwiaW5uZmx5dHRpbmdUaWxOb3JnZSI6W3siZnJhZmx5dHRpbmdzbGFuZCI6IkJFTCIsImZyYWZseXR0aW5nc3N0ZWRJVXRsYW5kZXQiOm51bGwsImZvbGtlcmVnaXN0ZXJtZXRhZGF0YSI6eyJham91cmhvbGRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTozNy41MzIiLCJneWxkaWdoZXRzdGlkc3B1bmt0IjoiMTk3Mi0wNy0wMVQwMDowMDowMCIsIm9wcGhvZXJzdGlkc3B1bmt0IjpudWxsLCJraWxkZSI6IkRvbGx5IiwiYWFyc2FrIjpudWxsLCJzZWt2ZW5zIjpudWxsfSwibWV0YWRhdGEiOnsib3BwbHlzbmluZ3NJZCI6IjUzNDVhZjc2LWFjMDMtNDQ2MS05ZDVjLWYxN2M0MmVhOGEzMiIsIm1hc3RlciI6IkZSRUciLCJlbmRyaW5nZXIiOlt7InR5cGUiOiJPUFBSRVRUIiwicmVnaXN0cmVydCI6IjIwMjItMDEtMTRUMTU6NDE6MzcuNTMyIiwicmVnaXN0cmVydEF2IjoiRm9sa2VyZWdpc3RlcmV0Iiwic3lzdGVta2lsZGUiOiJGUkVHIiwia2lsZGUiOiJEb2xseSJ9XSwiaGlzdG9yaXNrIjpmYWxzZX19XSwidXRmbHl0dGluZ0ZyYU5vcmdlIjpbXSwidmVyZ2VtYWFsRWxsZXJGcmVtdGlkc2Z1bGxtYWt0IjpbXX0sImhlbnRJZGVudGVyIjp7ImlkZW50ZXIiOlt7ImlkZW50IjoiMDEwNzcyMTEwMjciLCJoaXN0b3Jpc2siOmZhbHNlLCJncnVwcGUiOiJGT0xLRVJFR0lTVEVSSURFTlQiLCJtZXRhZGF0YSI6bnVsbCwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjpudWxsfSx7ImlkZW50IjoiMjU5NDgxOTgwNjU2MyIsImhpc3RvcmlzayI6ZmFsc2UsImdydXBwZSI6IkFLVE9SSUQiLCJtZXRhZGF0YSI6bnVsbCwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjpudWxsfV19fQo=', + CRM_Status__c = KafkaMessageService.STATUS_PENDING + ) + ); + Test.startTest(); + KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); + handler.processMessages(kafkaMessages); + List pl = [SELECT Id from Person__c where INT_ActorId__c = '2594819806563']; + Assert.areEqual(1, pl.size(), 'Expected one person inserted.'); + Test.stopTest(); + } + /********************* * TESTS FOR ISO MAP * *********************/ From fe109bbd89d67922b00679d0d4e7fb8cfc12d0f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 15 Jan 2024 15:48:43 +0100 Subject: [PATCH 005/159] delete other tests for now; they use KafkaPerson2 --- .../KafkaPdlPersondokumentHandlerTest.cls | 1487 ----------------- 1 file changed, 1487 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 6a0f8db6..533542f9 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -356,1491 +356,4 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual(1, pl.size(), 'Expected one person inserted.'); Test.stopTest(); } - - /********************* - * TESTS FOR ISO MAP * - *********************/ - - @IsTest - static void createIsoMapTest() { - Test.startTest(); - System.assertEquals( - 2, - KafkaPDLHandler2.createIsoMap( - [ - SELECT Name, CRM_Code__c - FROM Common_Code__c - WHERE CRM_Active__c = TRUE AND CRM_Code_Set__c IN ('Landkoder', 'LandkoderISO2') - ] - ) - .size(), - 'Expected two values' - ); - Test.stopTest(); - } - - @IsTest - static void getCountryFromIsoReturnNull() { - Test.startTest(); - System.assertEquals(null, new KafkaPDLHandler2().getCountryFromIso(null), 'Expected null in return'); - Test.stopTest(); - } - - @IsTest - static void getCountryFromIsoReturnCommonCode() { - Test.startTest(); - System.assertNotEquals(null, new KafkaPDLHandler2().getCountryFromIso('NOR'), 'Expected null in return'); - Test.stopTest(); - } - - @IsTest - static void getCountryNameFromIso() { - Test.startTest(); - System.assertEquals('Norge', new KafkaPDLHandler2().getCountryNameFromIso('NOR'), 'Expected Norge in return'); - Test.stopTest(); - } - - @IsTest - static void getCountrySfIdFromIso() { - Test.startTest(); - System.assertNotEquals( - null, - new KafkaPDLHandler2().getCountryIdFromIso('NOR'), - 'Did not expected null in return' - ); - Test.stopTest(); - } - - @IsTest - static void crateCitizenshipStringTest() { - Test.startTest(); - System.assertEquals( - 'Norge;India', - new KafkaPDLHandler2().crateCitizenshipString(new List{ 'NOR', 'IND' }), - 'Expected list with Norge and India' - ); - Test.stopTest(); - } - - /******************************************* - * TESTS FOR idents * - *******************************************/ - @isTest - static void setNameTest() { - KafkaPerson2 kPerson = createBaseKafkaPerson('1234567890123'); - - kPerson.identer.add(new PDL_IdentInformasjon()); - kPerson.identer[0].ident = '12345678901'; - kPerson.identer[0].historisk = false; - kPerson.identer[0].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - - kPerson.identer.add(new PDL_IdentInformasjon()); - kPerson.identer[1].ident = '12345678911'; - kPerson.identer[1].historisk = false; - kPerson.identer[1].gruppe = PDL_IdentGruppe.NPID; - - kPerson.identer.add(new PDL_IdentInformasjon()); - kPerson.identer[2].ident = '52345678901'; - kPerson.identer[2].historisk = false; - kPerson.identer[2].gruppe = PDL_IdentGruppe.AKTORID; - - kPerson.identer.add(new PDL_IdentInformasjon()); - kPerson.identer[3].ident = '12345678902'; - kPerson.identer[3].historisk = true; - kPerson.identer[3].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - - Person__c person = new Person__c(); - - KafkaPDLHandler2.setName(kPerson, person); - - System.assertEquals('12345678901', person.Name, 'Expected non historisk FOLKEREGISTERIDENT'); - - person = new Person__c(); - kPerson.identer[0].historisk = true; - KafkaPDLHandler2.setName(kPerson, person); - - System.assertEquals('12345678911', person.Name, 'Expected non historisk NPID'); - } - - @IsTest - static void setNameException() { - KafkaPerson2 kPerson = createBaseKafkaPerson('1234567890123'); - - kPerson.identer.add(new PDL_IdentInformasjon()); - kPerson.identer[0].ident = '12345678901'; - kPerson.identer[0].historisk = true; - kPerson.identer[0].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - - kPerson.identer.add(new PDL_IdentInformasjon()); - kPerson.identer[1].ident = '12345678911'; - kPerson.identer[1].historisk = true; - kPerson.identer[1].gruppe = PDL_IdentGruppe.NPID; - - kPerson.identer.add(new PDL_IdentInformasjon()); - kPerson.identer[2].ident = '52345678901'; - kPerson.identer[2].historisk = false; - kPerson.identer[2].gruppe = PDL_IdentGruppe.AKTORID; - - kPerson.identer.add(new PDL_IdentInformasjon()); - kPerson.identer[3].ident = '12345678902'; - kPerson.identer[3].historisk = true; - kPerson.identer[3].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - - Person__c person = new Person__c(); - - Test.startTest(); - try { - KafkaPDLHandler2.setName(kPerson, person); - System.assert(false, 'No exception thrown'); - } catch (KafkaPDLHandler2.PdlIdentException ex) { - System.assert(true); - } catch (Exception e) { - System.assert(false, 'Did not catch the correct exception'); - } - Test.stopTest(); - } - - @IsTest - static void setIdentsTest() { - KafkaPerson2 kPerson = createBaseKafkaPerson('1234567890123'); - - kPerson.identer.add(new PDL_IdentInformasjon()); - kPerson.identer[0].ident = '12345678901'; - kPerson.identer[0].historisk = false; - kPerson.identer[0].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - - kPerson.identer.add(new PDL_IdentInformasjon()); - kPerson.identer[1].ident = '12345678911'; - kPerson.identer[1].historisk = false; - kPerson.identer[1].gruppe = PDL_IdentGruppe.NPID; - - kPerson.identer.add(new PDL_IdentInformasjon()); - kPerson.identer[2].ident = '52345678901'; - kPerson.identer[2].historisk = true; - kPerson.identer[2].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - - kPerson.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); - kPerson.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; - kPerson.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; - kPerson.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; - kPerson.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); - kPerson.folkeregisteridentifikator[0].metadata.historisk = false; - - kPerson.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); - kPerson.folkeregisteridentifikator[1].identifikasjonsnummer = '52345678901'; - kPerson.folkeregisteridentifikator[1].status = PDL_IdentStatus.OPPHOERT; - kPerson.folkeregisteridentifikator[1].type = PDL_IdentType.DNR; - kPerson.folkeregisteridentifikator[1].metadata = new PDL_Metadata(); - kPerson.folkeregisteridentifikator[1].metadata.historisk = true; - - Person__c person = new Person__c(); - - Test.startTest(); - KafkaPDLHandler2.setIdents(kPerson, person); - Test.stopTest(); - - System.assertEquals(null, person.INT_ACTORID__c, 'Expected AKTORID to be null'); - System.assertEquals('12345678901', person.INT_FNR__c, 'Expected FNR to be set'); - System.assertEquals('12345678911', person.INT_NPID__c, 'Expect NPID to be set'); - System.assertEquals('52345678901', person.INT_DNR__c, 'Expect DNR to be set'); - } - - /******************************************* - * TESTS FOR checkLastUpdatedAndTombStones * - *******************************************/ - - //SCENARIO: - // A Person exists in Salesforce and we try to process a KafkaMessage__c where the CreatedDate is older than the Person LastModifiedDate - // KafkaMessage__c.CRM_Status__c should be set to error - @IsTest - static void checkLastUpdatedAndTombStonesOlderMessages() { - Person__c person1 = new Person__c(); - person1.INT_ActorId__c = '1000012345678'; - person1.Name = '20000000000'; - person1.INT_fnr__c = '20000000000'; - person1.INT_LastUpdatedFromPDL__c = Datetime.now(); - insert person1; - - String createdDate = Datetime.now().addDays(-2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); - KafkaMessage__c msg = (KafkaMessage__c) JSON.deserializeStrict( - '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + - createdDate + - '"}', - KafkaMessage__c.class - ); - msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; - msg.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":false}')); - - Test.startTest(); - new KafkaPDLHandler2().checkLastUpdatedAndTombStones(new List{ msg }); - Test.stopTest(); - - System.assertEquals( - KafkaMessageService.STATUS_WARNING, - msg.CRM_Status__c, - 'Expected the status to be set to error' - ); - } - - //SCENARIO: - // A Person exists in Salesforce and we try to process a KafkaMessage__c where the persons INT_LastUpdatedFromPDL__c is empty - // KafkaMessage__c.CRM_Status__c should not be updated - @IsTest - static void checkLastUpdatedAndTombStonesNewMessagesNoLastUpdated() { - Person__c person1 = new Person__c(); - person1.INT_ActorId__c = '1000012345678'; - person1.Name = '20000000000'; - person1.INT_fnr__c = '20000000000'; - person1.INT_LastUpdatedFromPDL__c = null; - insert person1; - - String createdDate = Datetime.now().addDays(2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); - KafkaMessage__c msg = (KafkaMessage__c) JSON.deserializeStrict( - '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + - createdDate + - '"}', - KafkaMessage__c.class - ); - msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; - msg.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":false}')); - - Test.startTest(); - new KafkaPDLHandler2().checkLastUpdatedAndTombStones(new List{ msg }); - Test.stopTest(); - - System.assertEquals( - KafkaMessageService.STATUS_PENDING, - msg.CRM_Status__c, - 'Expected the status to be the same' - ); - } - - //SCENARIO: - // A Person exists in Salesforce and we try to process a KafkaMessage__c where the CreatedDate is after than the Person INT_LastUpdatedFromPDL__c - // KafkaMessage__c.CRM_Status__c should not be updated - @IsTest - static void checkLastUpdatedAndTombStonesNewMessages() { - Person__c person1 = new Person__c(); - person1.INT_ActorId__c = '1000012345678'; - person1.Name = '20000000000'; - person1.INT_fnr__c = '20000000000'; - person1.INT_LastUpdatedFromPDL__c = Datetime.now(); - insert person1; - - String createdDate = Datetime.now().addDays(2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); - KafkaMessage__c msg = (KafkaMessage__c) JSON.deserializeStrict( - '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + - createdDate + - '"}', - KafkaMessage__c.class - ); - msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; - msg.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":false}')); - - Test.startTest(); - new KafkaPDLHandler2().checkLastUpdatedAndTombStones(new List{ msg }); - Test.stopTest(); - - System.assertEquals( - KafkaMessageService.STATUS_PENDING, - msg.CRM_Status__c, - 'Expected the status to be the same' - ); - } - - //SCENARIO: - // We try to process a KafkaMessage__c where we don't have any matching person in Salesforce - // KafkaMessage__c.CRM_Status__c should not be updated - @IsTest - static void checkLastUpdatedAndTombStonesBrandNewMessages() { - String createdDate = Datetime.now().addDays(2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); - KafkaMessage__c msg = (KafkaMessage__c) JSON.deserializeStrict( - '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + - createdDate + - '"}', - KafkaMessage__c.class - ); - msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; - msg.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":false}')); - - Test.startTest(); - new KafkaPDLHandler2().checkLastUpdatedAndTombStones(new List{ msg }); - Test.stopTest(); - - System.assertEquals( - KafkaMessageService.STATUS_PENDING, - msg.CRM_Status__c, - 'Expected the status to be the same' - ); - } - - //SCENARIO: - // We try to process several KafkaMessage__c where they all have the same key and matches a Person in Salesforce - // KafkaMessage__c.CRM_Status__c should be set to processec on only the oldest - @IsTest - static void checkLastUpdatedAndTombStonesNewDuplicateMessages() { - Person__c person1 = new Person__c(); - person1.INT_ActorId__c = '1000012345678'; - person1.Name = '20000000000'; - person1.INT_fnr__c = '20000000000'; - person1.INT_LastUpdatedFromPDL__c = Datetime.now(); - insert person1; - - String createdDate1 = Datetime.now().addDays(2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); - String createdDate2 = Datetime.now().addDays(3).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); - String createdDate3 = Datetime.now().addDays(1).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); - String createdDate4 = Datetime.now().addDays(-2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); - - KafkaMessage__c msg1 = (KafkaMessage__c) JSON.deserializeStrict( - '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + - createdDate1 + - '"}', - KafkaMessage__c.class - ); - msg1.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg1.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; - msg1.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":false}')); - - // The newest - KafkaMessage__c msg2 = (KafkaMessage__c) JSON.deserializeStrict( - '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + - createdDate2 + - '"}', - KafkaMessage__c.class - ); - msg2.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg2.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; - msg2.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":false}')); - - KafkaMessage__c msg3 = (KafkaMessage__c) JSON.deserializeStrict( - '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + - createdDate3 + - '"}', - KafkaMessage__c.class - ); - msg3.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg3.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; - msg3.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":false}')); - - KafkaMessage__c msg4 = (KafkaMessage__c) JSON.deserializeStrict( - '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + - createdDate4 + - '"}', - KafkaMessage__c.class - ); - msg4.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg4.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; - msg4.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":false}')); - - Test.startTest(); - new KafkaPDLHandler2().checkLastUpdatedAndTombStones(new List{ msg1, msg2, msg3, msg4 }); - Test.stopTest(); - - System.assertEquals( - KafkaMessageService.STATUS_PENDING, - msg1.CRM_Status__c, - 'Expected the status to be processed' - ); - System.assertEquals( - KafkaMessageService.STATUS_PENDING, - msg2.CRM_Status__c, - 'Expected the status to be the same' - ); - System.assertEquals( - KafkaMessageService.STATUS_PENDING, - msg3.CRM_Status__c, - 'Expected the status to be processed' - ); - System.assertEquals(KafkaMessageService.STATUS_WARNING, msg4.CRM_Status__c, 'Expected the status to be error'); - } - - //SCENARIO: - // We try to process two several KafkaMessage__c where they all have the same actorId that matches a Person in Salesforce, but one is a tombstone - // Both KafkaMessage__c should be processed - @IsTest - static void checkLastUpdatedAndTombStonesDuplicateMessagesWithTombstone() { - Person__c person1 = new Person__c(); - person1.INT_ActorId__c = '1000012345678'; - person1.Name = '20000000000'; - person1.INT_fnr__c = '20000000000'; - person1.INT_LastUpdatedFromPDL__c = Datetime.now(); - insert person1; - - String createdDate1 = Datetime.now().addDays(1).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); - String createdDate2 = Datetime.now().addDays(2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); - - KafkaMessage__c msg1 = (KafkaMessage__c) JSON.deserializeStrict( - '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + - createdDate1 + - '"}', - KafkaMessage__c.class - ); - msg1.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg1.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; - msg1.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":false}')); - - // The newest - KafkaMessage__c msg2 = (KafkaMessage__c) JSON.deserializeStrict( - '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + - createdDate2 + - '"}', - KafkaMessage__c.class - ); - msg2.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg2.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; - msg2.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":true}')); - - Test.startTest(); - new KafkaPDLHandler2().checkLastUpdatedAndTombStones(new List{ msg1, msg2 }); - Test.stopTest(); - - System.assertEquals( - KafkaMessageService.STATUS_WARNING, - msg1.CRM_Status__c, - 'Expected the status to be warning' - ); - System.assertEquals( - KafkaMessageService.STATUS_PENDING, - msg2.CRM_Status__c, - 'Expected the status to be pending' - ); - } - - //SCENARIO: - // We try process a KafkaMessage__c where we dont have a match a Person in Salesforce, but one is a tombstone - // KafkaMessage__c.CRM_Status__c should be set to processed - @IsTest - static void checkLastUpdatedAndTombStonesBrandNewMessagesWithTombstone() { - String createdDate1 = Datetime.now().addDays(1).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); - - KafkaMessage__c msg1 = (KafkaMessage__c) JSON.deserializeStrict( - '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + - createdDate1 + - '"}', - KafkaMessage__c.class - ); - msg1.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg1.CRM_Topic__c = 'teamnks.nks-sf-pdl-v3'; - msg1.CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":true}')); - - Test.startTest(); - new KafkaPDLHandler2().checkLastUpdatedAndTombStones(new List{ msg1 }); - Test.stopTest(); - - System.assertEquals( - KafkaMessageService.STATUS_PROCESSED, - msg1.CRM_Status__c, - 'Expected the status to be processed' - ); - } - - //SCENARIO: - // We try process a KafkaMessage__c where we have a match a Person in Salesforce, the message is a tombstone and the value is null - // Person should get a tombstone - @IsTest - static void processTombstoneTest() { - insert new Person__c( - Name = '12345678901', - INT_fnr__c = '12345678901', - INT_ActorId__c = '1000012345678', - INT_FirstName__c = 'FNAME', - INT_LastName__c = 'LNAME' - ); - - List kafkaMessages = new List(); - kafkaMessages.add( - new KafkaMessage__c( - CRM_Topic__c = 'teamnks.nks-sf-pdl-v3', - CRM_Key__c = EncodingUtil.base64Encode(Blob.valueOf('{"aktoer_id":"1000012345678","tombstone":true}')), - CRM_Value__c = null - ) - ); - - // Verify that we have only one Account - System.assertEquals(1, [SELECT COUNT() FROM Person__c]); - - // Act - Test.startTest(); - insert kafkaMessages; - System.debug([SELECT Id, CRM_Topic__c, CRM_Key__c, CRM_ErrorMessage__c FROM KafkaMessage__c]); - AsyncRequestSchedulable.enqueueAsyncJobs(); - Test.stopTest(); - System.debug([SELECT Id, CRM_Topic__c, CRM_Key__c, CRM_ErrorMessage__c FROM KafkaMessage__c]); - - // Assert that 1 Person Accounts have been inserted - System.assertEquals(1, [SELECT COUNT() FROM Person__c]); - - // Assert that all Kafka Message records have been marked as processed - System.assertEquals( - 1, - [SELECT COUNT() FROM KafkaMessage__c WHERE CRM_Status__c = :KafkaMessageService.STATUS_PROCESSED] - ); - - Person__c p = [ - SELECT Id, INT_ActorId__c, INT_fnr__c, Name, INT_IsHasTombstone__c, INT_FirstName__c, INT_LastName__c - FROM Person__c - LIMIT 1 - ]; - - // Assert that only tombstone and id fields has values - System.assertEquals('1000012345678', p.INT_ActorId__c, 'ActorId'); - System.assertEquals('12345678901', p.INT_fnr__c, 'fnr'); - System.assertEquals('12345678901', p.Name, 'Name'); - System.assertEquals(true, p.INT_IsHasTombstone__c, 'Tombstone'); - System.assertEquals(null, p.INT_FirstName__c, 'Firstname'); - System.assertEquals(null, p.INT_LastName__c, 'Lastname'); - } - - /******************************** - * TESTS FOR message processing * - ********************************/ - - @isTest - static void insertKafkaMessageOldVersion() { - KafkaPerson2 kafkaPerson = createBaseKafkaPersonOld('11223344556'); - kafkaPerson.folkeregisterId.add('12345678901'); - - KafkaMessage__c message = createKafkaMessageHelper(kafkaPerson, '11223344556', false); - - // Verify that we don't have any Person__c records - System.assertEquals(0, [SELECT COUNT() FROM Person__c]); - - // Act - Test.startTest(); - insert message; - AsyncRequestSchedulable.enqueueAsyncJobs(); - Test.stopTest(); - - isKafkaMessageProcessed( - [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message.Id LIMIT 1] - ); - - System.assertEquals(1, [SELECT COUNT() FROM Person__c]); - Person__c person = [ - SELECT FIELDS(STANDARD), INT_ActorId__c, INT_fnr__c, INT_dnr__c, INT_npid__c - FROM Person__c - WHERE INT_actorId__c = '11223344556' - ]; - - System.assertEquals(null, person.INT_fnr__c, 'Did not expect this value to be set'); - System.assertEquals(null, person.INT_npid__c, 'Did not expect this value to be set'); - System.assertEquals(null, person.INT_dnr__c, 'Did not expect this value to be set'); - System.assertEquals('12345678901', person.Name, 'Expected NAME to be set'); - System.assertEquals('11223344556', person.INT_actorId__c, 'Expected AKTØR ID to be set'); - } - - @isTest - static void insertKafkaMessageDefault() { - KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); - kafkaPerson.identer.add(new PDL_IdentInformasjon()); - kafkaPerson.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - kafkaPerson.identer[1].historisk = false; - kafkaPerson.identer[1].ident = '12345678901'; - kafkaPerson.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); - kafkaPerson.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; - kafkaPerson.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; - kafkaPerson.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; - kafkaPerson.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); - kafkaPerson.folkeregisteridentifikator[0].metadata.historisk = false; - - KafkaMessage__c message = createKafkaMessageHelper(kafkaPerson, '11223344556', false); - - // Verify that we don't have any Person__c records - System.assertEquals(0, [SELECT COUNT() FROM Person__c]); - - // Act - Test.startTest(); - insert message; - AsyncRequestSchedulable.enqueueAsyncJobs(); - Test.stopTest(); - - isKafkaMessageProcessed( - [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message.Id LIMIT 1] - ); - - System.assertEquals(1, [SELECT COUNT() FROM Person__c]); - Person__c person = [ - SELECT FIELDS(STANDARD), INT_ActorId__c, INT_fnr__c, INT_dnr__c, INT_npid__c - FROM Person__c - WHERE INT_actorId__c = '11223344556' - ]; - - System.assertEquals('12345678901', person.INT_fnr__c, 'Expect FNR to be set'); - System.assertEquals(null, person.INT_npid__c, 'Did not expect this value to be set'); - System.assertEquals(null, person.INT_dnr__c, 'Did not expect this value to be set'); - System.assertEquals('12345678901', person.Name, 'Expected NAME to be set'); - System.assertEquals('11223344556', person.INT_actorId__c, 'Expected AKTØR ID to be set'); - } - - @isTest - static void insertKafkaMessageProcessed() { - KafkaPerson2 kafkaPerson1 = createBaseKafkaPerson('11223344556'); - kafkaPerson1.identer.add(new PDL_IdentInformasjon()); - kafkaPerson1.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - kafkaPerson1.identer[1].historisk = false; - kafkaPerson1.identer[1].ident = '12345678901'; - kafkaPerson1.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); - kafkaPerson1.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; - kafkaPerson1.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; - kafkaPerson1.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; - kafkaPerson1.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); - kafkaPerson1.folkeregisteridentifikator[0].metadata.historisk = false; - - KafkaPerson2 kafkaPerson2 = createBaseKafkaPerson('11223344556'); - kafkaPerson2.identer.add(new PDL_IdentInformasjon()); - kafkaPerson2.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - kafkaPerson2.identer[1].historisk = false; - kafkaPerson2.identer[1].ident = '12345678901'; - kafkaPerson2.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); - kafkaPerson2.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; - kafkaPerson2.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; - kafkaPerson2.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; - kafkaPerson2.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); - kafkaPerson2.folkeregisteridentifikator[0].metadata.historisk = false; - kafkaPerson2.sikkerhetstiltak = new List(); - kafkaPerson2.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); - kafkaPerson2.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); - kafkaPerson2.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); - - KafkaPerson2 kafkaPerson3 = createBaseKafkaPerson('11223344556'); - kafkaPerson3.identer.add(new PDL_IdentInformasjon()); - kafkaPerson3.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - kafkaPerson3.identer[1].historisk = false; - kafkaPerson3.identer[1].ident = '12345678901'; - kafkaPerson3.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); - kafkaPerson3.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; - kafkaPerson3.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; - kafkaPerson3.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; - kafkaPerson3.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); - kafkaPerson3.folkeregisteridentifikator[0].metadata.historisk = false; - - KafkaMessage__c message1 = createKafkaMessageHelper(createBaseKafkaPerson('11223344557'), '11223344557', true); - KafkaMessage__c message2 = createKafkaMessageHelper(kafkaPerson1, '11223344556', false); - KafkaMessage__c message3 = createKafkaMessageHelper(kafkaPerson2, '11223344556', false); - KafkaMessage__c message4 = createKafkaMessageHelper(kafkaPerson3, '11223344556', true); - - // Act - Test.startTest(); - insert new List{ message1, message2, message3, message4 }; - AsyncRequestSchedulable.enqueueAsyncJobs(); - Test.stopTest(); - - message1 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message1.Id]; - message2 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message2.Id]; - message3 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message3.Id]; - message4 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message4.Id]; - - System.assertEquals( - KafkaMessageService.STATUS_PROCESSED, - message1.CRM_Status__c, - '' + message1.CRM_ErrorMessage__c - ); - System.assertEquals( - KafkaMessageService.STATUS_WARNING, - message2.CRM_Status__c, - '' + message2.CRM_ErrorMessage__c - ); - System.assertEquals( - KafkaMessageService.STATUS_WARNING, - message3.CRM_Status__c, - '' + message3.CRM_ErrorMessage__c - ); - System.assertEquals( - KafkaMessageService.STATUS_PROCESSED, - message4.CRM_Status__c, - '' + message4.CRM_ErrorMessage__c - ); - System.assertEquals(0, [SELECT COUNT() FROM Person__c WHERE Name = '12345678901']); - } - - @isTest - static void insertKafkaMessageWarning() { - KafkaPerson2 kafkaPerson1 = createBaseKafkaPerson('11223344556'); - kafkaPerson1.identer.add(new PDL_IdentInformasjon()); - kafkaPerson1.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - kafkaPerson1.identer[1].historisk = false; - kafkaPerson1.identer[1].ident = '12345678901'; - kafkaPerson1.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); - kafkaPerson1.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; - kafkaPerson1.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; - kafkaPerson1.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; - kafkaPerson1.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); - kafkaPerson1.folkeregisteridentifikator[0].metadata.historisk = false; - - KafkaPerson2 kafkaPerson2 = createBaseKafkaPerson('11223344556'); - kafkaPerson2.identer.add(new PDL_IdentInformasjon()); - kafkaPerson2.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - kafkaPerson2.identer[1].historisk = false; - kafkaPerson2.identer[1].ident = '12345678901'; - kafkaPerson2.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); - kafkaPerson2.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; - kafkaPerson2.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; - kafkaPerson2.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; - kafkaPerson2.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); - kafkaPerson2.folkeregisteridentifikator[0].metadata.historisk = false; - kafkaPerson2.sikkerhetstiltak = new List(); - kafkaPerson2.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); - kafkaPerson2.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); - kafkaPerson2.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); - - KafkaMessage__c message1 = createKafkaMessageHelper(createBaseKafkaPerson('11223344557'), '11223344557', true); - KafkaMessage__c message2 = createKafkaMessageHelper(kafkaPerson1, '11223344556', false); - KafkaMessage__c message3 = createKafkaMessageHelper(kafkaPerson2, '11223344556', false); - - // Act - Test.startTest(); - insert new List{ message1, message2, message3 }; - AsyncRequestSchedulable.enqueueAsyncJobs(); - Test.stopTest(); - - message1 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message1.Id]; - message2 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message2.Id]; - message3 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message3.Id]; - - System.assertEquals( - KafkaMessageService.STATUS_PROCESSED, - message1.CRM_Status__c, - '' + message1.CRM_ErrorMessage__c - ); - System.assertEquals( - KafkaMessageService.STATUS_PROCESSED, - message2.CRM_Status__c, - '' + message2.CRM_ErrorMessage__c - ); - System.assertEquals( - KafkaMessageService.STATUS_WARNING, - message3.CRM_Status__c, - '' + message3.CRM_ErrorMessage__c - ); - System.assertEquals(0, [SELECT COUNT() FROM Person__c WHERE Name = '12345678901']); - } - - @isTest - static void insertKafkaMessageUpdateError() { - insert new Person__c( - Name = '12345678901', - INT_fnr__c = '12345678901', - INT_ActorId__c = '11223344556', - INT_FirstName__c = 'FNAME', - INT_LastName__c = 'LNAME' - ); - - KafkaPerson2 kafkaPerson1 = createBaseKafkaPerson('11223344556'); - kafkaPerson1.identer.add(new PDL_IdentInformasjon()); - kafkaPerson1.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - kafkaPerson1.identer[1].historisk = false; - kafkaPerson1.identer[1].ident = '12345678901'; - kafkaPerson1.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); - kafkaPerson1.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; - kafkaPerson1.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; - kafkaPerson1.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; - kafkaPerson1.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); - kafkaPerson1.folkeregisteridentifikator[0].metadata.historisk = false; - - KafkaPerson2 kafkaPerson2 = createBaseKafkaPerson('11223344556'); - kafkaPerson2.identer.add(new PDL_IdentInformasjon()); - kafkaPerson2.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - kafkaPerson2.identer[1].historisk = false; - kafkaPerson2.identer[1].ident = '12345678901'; - kafkaPerson2.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); - kafkaPerson2.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; - kafkaPerson2.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; - kafkaPerson2.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; - kafkaPerson2.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); - kafkaPerson2.folkeregisteridentifikator[0].metadata.historisk = false; - kafkaPerson2.sikkerhetstiltak = new List(); - kafkaPerson2.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); - kafkaPerson2.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); - kafkaPerson2.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); - - KafkaPerson2 kafkaPerson3 = createBaseKafkaPerson('11223344559'); - kafkaPerson3.identer.add(new PDL_IdentInformasjon()); - kafkaPerson3.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - kafkaPerson3.identer[1].historisk = false; - kafkaPerson3.identer[1].ident = '12345678902'; - kafkaPerson3.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); - kafkaPerson3.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; - kafkaPerson3.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; - kafkaPerson3.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678902'; - kafkaPerson3.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); - kafkaPerson3.folkeregisteridentifikator[0].metadata.historisk = false; - - KafkaMessage__c message1 = createKafkaMessageHelper(createBaseKafkaPerson('11223344551'), '11223344551', true); - KafkaMessage__c message2 = createKafkaMessageHelper(kafkaPerson1, '11223344556', false); - KafkaMessage__c message3 = createKafkaMessageHelper(createBaseKafkaPerson('11223344553'), '11223344553', true); - KafkaMessage__c message4 = createKafkaMessageHelper(kafkaPerson2, '11223344556', false); - KafkaMessage__c message5 = createKafkaMessageHelper(createBaseKafkaPerson('11223344552'), '11223344552', true); - KafkaMessage__c message6 = createKafkaMessageHelper(kafkaPerson3, '11223344559', false); - - // Act - Test.startTest(); - insert new List{ message1, message2, message3, message4, message5, message6 }; - AsyncRequestSchedulable.enqueueAsyncJobs(); - Test.stopTest(); - - message1 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message1.Id]; - message2 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message2.Id]; - message3 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message3.Id]; - message4 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message4.Id]; - message5 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message5.Id]; - message6 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message6.Id]; - - System.assertEquals( - KafkaMessageService.STATUS_PROCESSED, - message1.CRM_Status__c, - '' + message1.CRM_ErrorMessage__c - ); - System.assertEquals( - KafkaMessageService.STATUS_PROCESSED, - message2.CRM_Status__c, - '' + message2.CRM_ErrorMessage__c - ); - System.assertEquals( - KafkaMessageService.STATUS_PROCESSED, - message3.CRM_Status__c, - '' + message3.CRM_ErrorMessage__c - ); - System.assertEquals( - KafkaMessageService.STATUS_ERROR, - message4.CRM_Status__c, - '' + message4.CRM_ErrorMessage__c - ); - System.assertEquals( - KafkaMessageService.STATUS_PROCESSED, - message5.CRM_Status__c, - '' + message5.CRM_ErrorMessage__c - ); - System.assertEquals( - KafkaMessageService.STATUS_PROCESSED, - message6.CRM_Status__c, - '' + message6.CRM_ErrorMessage__c - ); - System.assertEquals(1, [SELECT COUNT() FROM Person__c WHERE Name = '12345678901']); - System.assertEquals(1, [SELECT COUNT() FROM Person__c WHERE Name = '12345678902']); - } - - @isTest - static void insertKafkaMessageNpidPerson() { - KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); - - kafkaPerson.identer.add(new PDL_IdentInformasjon()); - kafkaPerson.identer[1].gruppe = PDL_IdentGruppe.NPID; - kafkaPerson.identer[1].historisk = false; - kafkaPerson.identer[1].ident = '12345678901'; - - kafkaPerson.folkeregisterpersonstatus.clear(); - - KafkaMessage__c message = createKafkaMessageHelper(kafkaPerson, '11223344556', false); - - // Act - Test.startTest(); - insert message; - AsyncRequestSchedulable.enqueueAsyncJobs(); - Test.stopTest(); - - isKafkaMessageProcessed( - [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message.Id LIMIT 1] - ); - - System.assertEquals(1, [SELECT COUNT() FROM Person__c]); - - Person__c person = [ - SELECT FIELDS(STANDARD), INT_ActorId__c, INT_fnr__c, INT_dnr__c, INT_npid__c - FROM Person__c - WHERE INT_actorId__c = '11223344556' - ]; - - System.assertEquals(null, person.INT_fnr__c, 'Did not expect this value to be set'); - System.assertEquals('12345678901', person.INT_npid__c, 'Expect this value to be set'); - System.assertEquals(null, person.INT_dnr__c, 'Did not expect this value to be set'); - System.assertEquals('12345678901', person.Name, 'Expected NAME to be set'); - System.assertEquals('11223344556', person.INT_actorId__c, 'Expected AKTØR ID to be set'); - } - - @isTest - static void insertKafkaMessageNpidPersonFromNpidToFnr() { - KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); - - kafkaPerson.identer.add(new PDL_IdentInformasjon()); - kafkaPerson.identer[1].gruppe = PDL_IdentGruppe.NPID; - kafkaPerson.identer[1].historisk = false; - kafkaPerson.identer[1].ident = '12345678901'; - - kafkaPerson.folkeregisterpersonstatus.clear(); - - KafkaMessage__c message1 = createKafkaMessageHelper(kafkaPerson, '11223344556', false); - - kafkaPerson.identer.add(new PDL_IdentInformasjon()); - kafkaPerson.identer[2].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - kafkaPerson.identer[2].historisk = false; - kafkaPerson.identer[2].ident = '52345678901'; - - kafkaPerson.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); - kafkaPerson.folkeregisteridentifikator[0].identifikasjonsnummer = '52345678901'; - kafkaPerson.folkeregisteridentifikator[0].type = PDL_IdentType.DNR; - kafkaPerson.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; - kafkaPerson.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); - kafkaPerson.folkeregisteridentifikator[0].metadata.historisk = false; - - kafkaPerson.folkeregisterpersonstatus.add('bosatt'); - - KafkaMessage__c message2 = createKafkaMessageHelper(kafkaPerson, '11223344556', false); - - kafkaPerson.identer[2].historisk = true; - - kafkaPerson.identer.add(new PDL_IdentInformasjon()); - kafkaPerson.identer[3].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - kafkaPerson.identer[3].historisk = false; - kafkaPerson.identer[3].ident = '11345678901'; - - kafkaPerson.folkeregisteridentifikator[0].status = PDL_IdentStatus.OPPHOERT; - kafkaPerson.folkeregisteridentifikator[0].metadata.historisk = true; - - kafkaPerson.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); - kafkaPerson.folkeregisteridentifikator[1].identifikasjonsnummer = '11345678901'; - kafkaPerson.folkeregisteridentifikator[1].type = PDL_IdentType.FNR; - kafkaPerson.folkeregisteridentifikator[1].status = PDL_IdentStatus.I_BRUK; - kafkaPerson.folkeregisteridentifikator[1].metadata = new PDL_Metadata(); - kafkaPerson.folkeregisteridentifikator[1].metadata.historisk = false; - - KafkaMessage__c message3 = createKafkaMessageHelper(kafkaPerson, '11223344556', false); - - KafkaMessageService msgService; - Person__c person; - - // Act - Test.startTest(); - - //Message 1 - insert message1; - msgService = new KafkaMessageService(new List{ message1 }); - msgService.handleMessages(); - - isKafkaMessageProcessed( - [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message1.Id LIMIT 1] - ); - System.assertEquals(1, [SELECT COUNT() FROM Person__c]); - person = [ - SELECT FIELDS(STANDARD), INT_ActorId__c, INT_fnr__c, INT_dnr__c, INT_npid__c - FROM Person__c - WHERE INT_actorId__c = '11223344556' - ]; - System.assertEquals('11223344556', person.INT_actorId__c, 'Expected AKTØR ID to be set'); - System.assertEquals(null, person.INT_fnr__c, 'Did not expect FNR to be set'); - System.assertEquals('12345678901', person.INT_npid__c, 'Expected NPID to be set'); - System.assertEquals(null, person.INT_dnr__c, 'Did not expect DNR to be set'); - System.assertEquals('12345678901', person.Name, 'Expected NAME to be same as NPID'); - - //Message 2 - insert message2; - msgService = new KafkaMessageService(new List{ message2 }); - msgService.handleMessages(); - - isKafkaMessageProcessed( - [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message2.Id LIMIT 1] - ); - System.assertEquals(1, [SELECT COUNT() FROM Person__c]); - person = [ - SELECT FIELDS(STANDARD), INT_ActorId__c, INT_fnr__c, INT_dnr__c, INT_npid__c - FROM Person__c - WHERE INT_actorId__c = '11223344556' - ]; - System.assertEquals('11223344556', person.INT_actorId__c, 'Expected AKTØR ID to be set'); - System.assertEquals(null, person.INT_fnr__c, 'Did not expect FNR to be set'); - System.assertEquals('12345678901', person.INT_npid__c, 'Expected NPID to be set'); - System.assertEquals('52345678901', person.INT_dnr__c, 'Expected DNR to be set'); - System.assertEquals('52345678901', person.Name, 'Expected NAME to be same as DNR'); - - //Message 3 - insert message3; - msgService = new KafkaMessageService(new List{ message3 }); - msgService.handleMessages(); - - isKafkaMessageProcessed( - [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message3.Id LIMIT 1] - ); - System.assertEquals(1, [SELECT COUNT() FROM Person__c]); - person = [ - SELECT FIELDS(STANDARD), INT_ActorId__c, INT_fnr__c, INT_dnr__c, INT_npid__c - FROM Person__c - WHERE INT_actorId__c = '11223344556' - ]; - - System.assertEquals('11223344556', person.INT_actorId__c, 'Expected AKTØR ID to be set'); - System.assertEquals('11345678901', person.INT_fnr__c, 'Expected FNR to be set'); - System.assertEquals('12345678901', person.INT_npid__c, 'Expected NPID to be set'); - System.assertEquals('52345678901', person.INT_dnr__c, 'Expect DNR to be set'); - System.assertEquals('11345678901', person.Name, 'Expected NAME to be same as FNR'); - - Test.stopTest(); - } - - /*************************** - * VERIFY THE DATA MAPPING * - **************************/ - - @isTest - static void mapFieldValuesExcludingAddresses() { - KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); - kafkaPerson.identer.add(new PDL_IdentInformasjon()); - kafkaPerson.identer[1].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - kafkaPerson.identer[1].historisk = false; - kafkaPerson.identer[1].ident = '12345678901'; - kafkaPerson.folkeregisteridentifikator.add(new PDL_FolkeregisterIdentifikator()); - kafkaPerson.folkeregisteridentifikator[0].identifikasjonsnummer = '12345678901'; - kafkaPerson.folkeregisteridentifikator[0].type = PDL_IdentType.FNR; - kafkaPerson.folkeregisteridentifikator[0].status = PDL_IdentStatus.I_BRUK; - kafkaPerson.folkeregisteridentifikator[0].metadata = new PDL_Metadata(); - kafkaPerson.folkeregisteridentifikator[0].metadata.historisk = false; - - kafkaPerson.navn[0].fornavn = 'TEST'; - kafkaPerson.navn[0].mellomnavn = 'T.'; - - kafkaPerson.foedselsdato.add('2020-02-25'); - - kafkaPerson.innflyttingTilNorge.add(new PDL_InnflyttingTilNorge()); - kafkaPerson.innflyttingTilNorge[0].fraflyttingsland = 'IND'; - kafkaPerson.innflyttingTilNorge[0].fraflyttingsstedIUtlandet = 'Delhi'; - - kafkaPerson.sikkerhetstiltak = new List(); - kafkaPerson.sikkerhetstiltak.add(new PersonJSONFieldObjects.Sikkerhetstiltak()); - kafkaPerson.sikkerhetstiltak[0].beskrivelse = 'Telefonisk utestengelse'; - kafkaPerson.sikkerhetstiltak[0].tiltaksType = 'TFUS'; - kafkaPerson.sikkerhetstiltak[0].gyldigFraOgMed = '2020-12-14'; - kafkaPerson.sikkerhetstiltak[0].gyldigTilOgMed = '2020-12-20'; - kafkaPerson.sikkerhetstiltak[0].kontaktPersonId = 'Z000000'; - kafkaPerson.sikkerhetstiltak[0].kontaktPersonEnhet = '0000'; - - kafkaPerson.statsborgerskap.add('NOR'); - - kafkaPerson.sivilstand.add(new PDL_Sivilstand()); - kafkaPerson.sivilstand[0].type = PDL_Sivilstandstype.GIFT; - kafkaPerson.sivilstand[0].gyldigFraOgMed = Date.newInstance(2001, 6, 20); - kafkaPerson.sivilstand[0].relatertVedSivilstand = '12345678910'; - - kafkaPerson.kjoenn.add('MANN'); - - kafkaPerson.doedsfall.add(new KafkaPerson2.Doedsfall()); - kafkaPerson.doedsfall[0].doedsdato = '2019-01-29'; - kafkaPerson.doedsfall[0].master = 'FREG'; - - kafkaPerson.telefonnummer.add(new KafkaPerson2.Telefonnummer()); - kafkaPerson.telefonnummer[0].landskode = '+46'; - kafkaPerson.telefonnummer[0].nummer = '123456789'; - kafkaPerson.telefonnummer[0].prioritet = '2'; - kafkaPerson.telefonnummer.add(new KafkaPerson2.Telefonnummer()); - kafkaPerson.telefonnummer[1].landskode = '+47'; - kafkaPerson.telefonnummer[1].nummer = '987654321'; - kafkaPerson.telefonnummer[1].prioritet = '1'; - - kafkaPerson.utflyttingFraNorge.add(new PDL_UtflyttingFraNorge()); - kafkaPerson.utflyttingFraNorge[0].tilflyttingsland = 'IND'; - kafkaPerson.utflyttingFraNorge[0].tilflyttingsstedIUtlandet = 'Delhi'; - - kafkaPerson.talesspraaktolk = new List(); - kafkaPerson.talesspraaktolk.add('NO'); - - kafkaPerson.fullmakt = new List(); - kafkaPerson.fullmakt.add(new PersonJSONFieldObjects.Fullmakt()); - kafkaPerson.fullmakt[0].motpartsRolle = 'Fullmektig'; - kafkaPerson.fullmakt[0].motpartsPersonident = '12345678910'; - kafkaPerson.fullmakt[0].omraader = new List{ 'DAG' }; - kafkaPerson.fullmakt[0].gyldigFraOgMed = '2020-02-14'; - kafkaPerson.fullmakt[0].gyldigTilOgMed = '2020-02-28'; - - kafkaPerson.vergemaalEllerFremtidsfullmakt = new List(); - kafkaPerson.vergemaalEllerFremtidsfullmakt.add(new PersonJSONFieldObjects.VergemaalEllerFremtidsfullmakt()); - kafkaPerson.vergemaalEllerFremtidsfullmakt[0].type = 'stadfestetFremtidsfullmakt'; - kafkaPerson.vergemaalEllerFremtidsfullmakt[0].embete = 'Statsforvalter'; - kafkaPerson.vergemaalEllerFremtidsfullmakt[0].navn = null; - kafkaPerson.vergemaalEllerFremtidsfullmakt[0].motpartsPersonident = '12345678910'; - kafkaPerson.vergemaalEllerFremtidsfullmakt[0].omfang = 'Personlige og/eller økonomiske interesser'; - kafkaPerson.vergemaalEllerFremtidsfullmakt[0].omfangetErInnenPersonligOmraade = true; - - KafkaMessage__c message = createKafkaMessageHelper(kafkaPerson, '11223344556', false); - - Test.startTest(); - insert message; - AsyncRequestSchedulable.enqueueAsyncJobs(); - Test.stopTest(); - - isKafkaMessageProcessed( - [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message.Id LIMIT 1] - ); - - Person__c person = getPersonAccountByActorIdent().get('11223344556'); - - System.assertEquals('11223344556', person.INT_actorId__c, 'Expected AKTØR ID to be set'); - System.assertEquals('12345678901', person.INT_fnr__c, 'Expected FNR to be set'); - System.assertEquals(null, person.INT_npid__c, 'Expected NPID to be null'); - System.assertEquals(null, person.INT_dnr__c, 'Expect DNR to be null'); - System.assertEquals('12345678901', person.Name, 'Expected NAME to be same as FNR'); - - System.assertEquals('2020-02-25', person.INT_DateOfBirth__c, 'Expected '); - - System.assertEquals('TEST', person.INT_FirstName__c, 'Expected '); - System.assertEquals('T.', person.INT_MiddleName__c, 'Expected '); - System.assertEquals('TESTESEN', person.INT_LastName__c, 'Expected '); - - System.assertEquals('Bosatt', person.INT_LegalStatus__c, 'Expected '); - - System.assertNotEquals(null, person.INT_MovedFromCountry__c, 'Expected '); - System.assertEquals('Delhi', person.INT_MovedFromPlace__c, 'Expected '); - - System.assertEquals('UGRADERT', person.INT_Confidential__c, 'Expected '); - - System.assert(String.isNotBlank(person.INT_SecurityMeasures__c), 'Expected '); - - System.assertEquals('Norge', person.INT_Citizenships__c, 'Expected '); - - System.assertEquals('GIFT', person.INT_MaritalStatus__c, 'Expected '); - System.assertEquals(Date.newInstance(2001, 6, 20), person.INT_MaritalStatusDate__c, 'Expected '); - System.assertEquals('12345678910', person.INT_MaritalRelation__c, 'Expected '); - - System.assertEquals('Mann', person.INT_Sex__c, 'Expected '); - - System.assertEquals(Date.newInstance(2019, 1, 29), person.INT_DateOfDeath__c, 'Expected '); - System.assertEquals(true, person.INT_IsDeceased__c, 'Expected '); - - System.assertEquals('+47987654321', person.INT_Phone1__c, 'Expected '); - System.assertEquals('+46123456789', person.INT_Phone2__c, 'Expected '); - - System.assertNotEquals(null, person.INT_MovedToCountry__c, 'Expected '); - System.assertEquals('Delhi', person.INT_MovedToPlace__c, 'Expected '); - - System.assertEquals('NO', person.INT_SpokenLanguageIntepreter__c, 'Expected '); - - System.assert(String.isNotBlank(person.INT_PowerOfAttorney__c), 'Expected '); - System.assert(String.isNotBlank(person.INT_GuardianshipOrFuturePowerOfAttorney__c), 'Expected '); - } - - /*********************** - * TEST ADDRESS AND GT * - **********************/ - - @IsTest - static void setBostedVegadresse() { - Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); - KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); - kafkaPerson.bostedsadresse.vegadresse.add(new KafkaPerson2.Vegadresse()); - kafkaPerson.bostedsadresse.vegadresse[0].adressenavn = 'Testveien'; - kafkaPerson.bostedsadresse.vegadresse[0].husnummer = '1'; - kafkaPerson.bostedsadresse.vegadresse[0].husbokstav = 'A'; - kafkaPerson.bostedsadresse.vegadresse[0].postnummer = '0001'; - kafkaPerson.bostedsadresse.vegadresse[0].kommunenummer = '4321'; - kafkaPerson.bostedsadresse.vegadresse[0].bydelsnummer = '030110'; - kafkaPerson.bostedsadresse.vegadresse[0].koordinater = 'x=354424, y=6862099, z=0'; - - Test.startTest(); - KafkaPDLHandler2 handler = new KafkaPDLHandler2(); - handler.setAddress(person, kafkaPerson); - Test.stopTest(); - - System.assertEquals( - 'Testveien 1 A', - person.INT_ResidentialAddress__c, - 'Expected residential address to be set correctly' - ); - System.assertEquals('0001', person.INT_ResidentialZipCode__c, 'Expected residential zip code to be set'); - System.assertEquals( - '4321', - person.INT_AddressMunicipalityNumber__c, - 'Expected Address Municipality number to be set' - ); - System.assertEquals( - '030110', - person.INT_AddressDistrictNumber__c, - 'Expected Address District number to be set' - ); - System.assertEquals('x=354424, y=6862099, z=0', person.INT_Coordinates__c, 'Expected coordinates to be set'); - - System.assertEquals(null, person.INT_TemporaryAddress__c, 'Expected INT_TemporaryAddress__c to be null'); - System.assertEquals(null, person.INT_TemporaryZipCode__c, 'Expected INT_TemporaryZipCode__c to be null'); - System.assertEquals( - null, - person.INT_TemporaryMunicipalityNumber__c, - 'Expected INT_TemporaryMunicipalityNumber__c to be null' - ); - System.assertEquals( - null, - person.INT_TemporaryCoordinates__c, - 'Expected INT_TemporaryCoordinates__c to be null' - ); - System.assertEquals( - null, - person.INT_TemporaryCountryCode__c, - 'Expected INT_TemporaryCountryCode__c to be null' - ); - } - - @IsTest - static void setOppholdVegadresse() { - Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); - KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); - kafkaPerson.oppholdsadresse.vegadresse.add(new KafkaPerson2.Vegadresse()); - kafkaPerson.oppholdsadresse.vegadresse[0].adressenavn = 'Testveien'; - kafkaPerson.oppholdsadresse.vegadresse[0].husnummer = '1'; - kafkaPerson.oppholdsadresse.vegadresse[0].husbokstav = 'A'; - kafkaPerson.oppholdsadresse.vegadresse[0].postnummer = '0001'; - kafkaPerson.oppholdsadresse.vegadresse[0].kommunenummer = '4321'; - kafkaPerson.oppholdsadresse.vegadresse[0].bydelsnummer = '030110'; - kafkaPerson.oppholdsadresse.vegadresse[0].koordinater = 'x=354424, y=6862099, z=0'; - - Test.startTest(); - KafkaPDLHandler2 handler = new KafkaPDLHandler2(); - handler.setAddress(person, kafkaPerson); - Test.stopTest(); - - System.assertEquals(null, person.INT_ResidentialAddress__c, 'Expected INT_ResidentialAddress__c to be null'); - System.assertEquals(null, person.INT_ResidentialZipCode__c, 'Expected INT_ResidentialZipCode__c to be null'); - System.assertEquals( - null, - person.INT_AddressMunicipalityNumber__c, - 'Expected INT_AddressMunicipalityNumber__c to be null' - ); - System.assertEquals( - null, - person.INT_AddressDistrictNumber__c, - 'Expected INT_AddressDistrictNumber__c to be null' - ); - System.assertEquals(null, person.INT_Coordinates__c, 'Expected INT_Coordinates__c to be null'); - - System.assertEquals( - 'Testveien 1 A', - person.INT_TemporaryAddress__c, - 'Expected residential address to be set correctly' - ); - System.assertEquals('0001', person.INT_TemporaryZipCode__c, 'Expected residential zip code to be set'); - System.assertEquals( - '4321', - person.INT_TemporaryMunicipalityNumber__c, - 'Expected Address Municipality number to be set' - ); - System.assertEquals( - 'x=354424, y=6862099, z=0', - person.INT_TemporaryCoordinates__c, - 'Expected coordinates to be set' - ); - System.assertEquals( - null, - person.INT_TemporaryCountryCode__c, - 'Expected INT_TemporaryCountryCode__c to be null' - ); - } - @IsTest - static void setGTFromKommunenummer() { - Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); - KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); - kafkaPerson.kommunenummerFraGt = '0301'; - kafkaPerson.bydelsnummerFraGt = '030101'; - - Test.startTest(); - KafkaPDLHandler2 handler = new KafkaPDLHandler2(); - handler.setMunicipalityAndGT(person, kafkaPerson); - Test.stopTest(); - - System.assertEquals( - '0301', - person.INT_GTMunicipalityNumber__c, - 'Expected INT_GTMunicipalityNumber__c to be set' - ); - System.assertEquals('030101', person.INT_GTDistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - System.assertEquals('03', person.INT_RegionNumber__c, 'Expected INT_RegionNumber__c to be set'); - System.assertEquals('0301', person.INT_MunicipalityNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - System.assertEquals('030101', person.INT_DistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - } - - @IsTest - static void setGTFromKommunenummerNoDistrict() { - Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); - KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); - kafkaPerson.kommunenummerFraGt = '0301'; - - Test.startTest(); - KafkaPDLHandler2 handler = new KafkaPDLHandler2(); - handler.setMunicipalityAndGT(person, kafkaPerson); - Test.stopTest(); - - System.assertEquals( - '0301', - person.INT_GTMunicipalityNumber__c, - 'Expected INT_GTMunicipalityNumber__c to be set' - ); - System.assertEquals(null, person.INT_GTDistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - System.assertEquals('03', person.INT_RegionNumber__c, 'Expected INT_RegionNumber__c to be set'); - System.assertEquals('0301', person.INT_MunicipalityNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - System.assertEquals(null, person.INT_DistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - } - - @IsTest - static void setGTFromKommunenummerFromAddressOnly() { - Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); - KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); - kafkaPerson.bostedsadresse.vegadresse.add(new KafkaPerson2.Vegadresse()); - kafkaPerson.bostedsadresse.vegadresse[0].adressenavn = 'Testveien'; - kafkaPerson.bostedsadresse.vegadresse[0].adressenavn = '1'; - kafkaPerson.bostedsadresse.vegadresse[0].adressenavn = 'A'; - kafkaPerson.bostedsadresse.vegadresse[0].postnummer = '0001'; - kafkaPerson.bostedsadresse.vegadresse[0].kommunenummer = '4321'; - kafkaPerson.bostedsadresse.vegadresse[0].bydelsnummer = '030110'; - kafkaPerson.bostedsadresse.vegadresse[0].koordinater = 'x=354424, y=6862099, z=0'; - - Test.startTest(); - KafkaPDLHandler2 handler = new KafkaPDLHandler2(); - handler.setAddress(person, kafkaPerson); - handler.setMunicipalityAndGT(person, kafkaPerson); - Test.stopTest(); - - System.assertEquals(null, person.INT_GTMunicipalityNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - System.assertEquals(null, person.INT_GTDistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - System.assertEquals(null, person.INT_RegionNumber__c, 'Expected INT_RegionNumber__c to be set'); - System.assertEquals('4321', person.INT_MunicipalityNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - System.assertEquals('030110', person.INT_DistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - } - - /*********** - * HELPERS * - **********/ - private static void isKafkaMessageProcessed(KafkaMessage__c message) { - System.assertEquals( - KafkaMessageService.STATUS_PROCESSED, - message.CRM_Status__c, - 'Expected message to be processed but it is ' + - message.CRM_Status__c + - '. CRM_ErrorMessage__c: ' + - message.CRM_ErrorMessage__c - ); - } - - private static KafkaPerson2 createBaseKafkaPersonOld(String actorId) { - KafkaPerson2 kafkaPerson = createBaseKafkaPerson(actorId); - kafkaPerson.aktoerId = actorId; - kafkaPerson.folkeregisterId = new List(); - kafkaPerson.folkeregisteridentifikator = null; - kafkaPerson.identer = null; - return kafkaPerson; - } - - private static KafkaPerson2 createBaseKafkaPerson(String actorId) { - KafkaPerson2 kafkaPerson = new KafkaPerson2(); - kafkaPerson.identer = new List(); - kafkaPerson.folkeregisteridentifikator = new List(); - kafkaPerson.foedselsdato = new List(); - kafkaPerson.folkeregisterpersonstatus = new List(); - kafkaPerson.navn = new List(); - kafkaPerson.bostedsadresse = new KafkaPerson2.Adresser(); - kafkaPerson.bostedsadresse.vegadresse = new List(); - kafkaPerson.bostedsadresse.matrikkeladresse = new List(); - kafkaPerson.bostedsadresse.utenlandskAdresse = new List(); - kafkaPerson.bostedsadresse.ukjentBosted = new List(); - kafkaPerson.oppholdsadresse = new KafkaPerson2.Adresser(); - kafkaPerson.oppholdsadresse.vegadresse = new List(); - kafkaPerson.oppholdsadresse.matrikkeladresse = new List(); - kafkaPerson.oppholdsadresse.utenlandskAdresse = new List(); - kafkaPerson.oppholdsadresse.ukjentBosted = new List(); - kafkaPerson.innflyttingTilNorge = new List(); - kafkaPerson.utflyttingFraNorge = new List(); - kafkaPerson.adressebeskyttelse = new List(); - kafkaPerson.kommunenummerFraGt = ''; - kafkaPerson.bydelsnummerFraGt = ''; - kafkaPerson.sivilstand = new List(); - kafkaPerson.statsborgerskap = new List(); - kafkaPerson.kjoenn = new List(); - kafkaPerson.doedsfall = new List(); - kafkaPerson.telefonnummer = new List(); - - //Default values - //Ident - kafkaPerson.identer.add(new PDL_IdentInformasjon()); - kafkaPerson.identer[0].gruppe = PDL_IdentGruppe.AKTORID; - kafkaPerson.identer[0].historisk = false; - kafkaPerson.identer[0].ident = actorId; - //Person status - kafkaPerson.folkeregisterpersonstatus.add('bosatt'); - //Navn - kafkaPerson.navn.add(new PDL_Navn()); - kafkaPerson.navn[0].etternavn = 'TESTESEN'; - kafkaPerson.adressebeskyttelse.add('UGRADERT'); - - return kafkaPerson; - } - - private static KafkaMessage__c createKafkaMessageHelper( - KafkaPerson2 kafkaPerson, - String aktorId, - Boolean tombstone - ) { - KafkaMessage__c kafkaMessage = new KafkaMessage__c( - CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf(JSON.serialize(kafkaPerson))), - CRM_Key__c = EncodingUtil.base64Encode( - Blob.valueOf('{"aktoer_id":"' + aktorId + '","tombstone":' + tombstone + '}') - ), - CRM_Topic__c = 'teamnks.nks-sf-pdl-v3' - ); - - return kafkaMessage; - } - - private static Map getPersonAccountByActorIdent() { - Map personByActorIdent = new Map(); - for (Person__c person : [ - SELECT - Id, - Name, - INT_ActorId__c, - INT_AddressDistrictNumber__c, - INT_AddressMunicipalityNumber__c, - INT_Citizenships__c, - INT_Confidential__c, - INT_Coordinates__c, - INT_DateOfBirth__c, - INT_DateOfDeath__c, - INT_DistrictNumber__c, - INT_dnr__c, - INT_FamilyRelations__c, - INT_fnr__c, - INT_FirstName__c, - INT_GTDistrictNumber__c, - INT_GTMunicipalityNumber__c, - INT_GuardianshipOrFuturePowerOfAttorney__c, - INT_IsDeceased__c, - INT_IsNavEmployee__c, - INT_LastName__c, - INT_LastUpdatedFromPDL__c, - INT_LastUpdatedFromKRR__c, - INT_LegalStatus__c, - INT_MaritalRelation__c, - INT_MaritalStatus__c, - INT_MaritalStatusDate__c, - INT_MiddleName__c, - INT_MovedFromCountry__c, - INT_MovedFromPlace__c, - INT_MovedToCountry__c, - INT_MovedToPlace__c, - INT_MunicipalityNumber__c, - INT_npid__c, - INT_Phone1__c, - INT_Phone2__c, - INT_PowerOfAttorney__c, - INT_RegionNumber__c, - INT_ResidentialAddress__c, - INT_ResidentialZipCode__c, - INT_SecurityMeasures__c, - INT_Sex__c, - INT_SpokenLanguageIntepreter__c, - INT_TemporaryAddress__c, - INT_TemporaryCountryCode__c, - INT_TemporaryMunicipalityNumber__c, - INT_TemporaryZipCode__c, - INT_TemporaryCoordinates__c - FROM Person__c - ]) { - personByActorIdent.put(person.INT_ActorId__c, person); - } - return personByActorIdent; - } } From a7d3639938327c819d7a256fba39638d04a391bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 15 Jan 2024 15:56:25 +0100 Subject: [PATCH 006/159] create person with fnr --- .../classes/KafkaPdlPersondokumentHandler.cls | 71 +++++++++++-------- .../pdl-handler/classes/KafkaPerson3.cls | 12 ++++ .../classes/KafkaPerson3.cls-meta.xml | 5 ++ 3 files changed, 59 insertions(+), 29 deletions(-) create mode 100644 force-app/pdl-handler/classes/KafkaPerson3.cls create mode 100644 force-app/pdl-handler/classes/KafkaPerson3.cls-meta.xml diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index c52d99d7..2ad4897c 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -2,6 +2,7 @@ * Yes, just a copy of KafkaPDLHandler2 for now. */ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMessageConsumer { + @TestVisible private static final String PDL_ERROR_STRING = ''; @@ -33,7 +34,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess //If we have a message where the created date is older than last updated, set it to error so that we can investigate it. //If we have a tombstone without a person in Salesforce, set it to processed. - checkLastUpdatedAndTombStones(messages); + //checkLastUpdatedAndTombStones(messages); // Errors are caught and saved on each KafkaMessage record for (KafkaMessage__c msg : messages) { @@ -47,7 +48,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess String errorMsg = e.getTypeName() + ': ' + e.getMessage() + ' (' + e.getLineNumber() + ')'; setMessageError(errorMsg, msg, KafkaMessageService.STATUS_ERROR); logger.error( - 'Error creatign Person__c from PDL Kafka message. ' + + 'Error creating Person__c from PDL Kafka message. ' + '\n ' + e.getMessage() + '\n Kafka key reference: ' + @@ -60,7 +61,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess setMessageError(errorMsg, msg); if (msg.CRM_Status__c == KafkaMessageService.STATUS_ERROR) { logger.error( - 'Error creatign Person__c from PDL Kafka message. ' + + 'Error creating Person__c from PDL Kafka message. ' + '\n Kafka key reference: ' + msg.CRM_Key__c, null, @@ -68,7 +69,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess ); } else if (msg.CRM_Status__c == KafkaMessageService.STATUS_WARNING) { logger.warning( - 'Warning creatign Person__c from PDL Kafka message. ' + + 'Warning creating Person__c from PDL Kafka message. ' + '\n Kafka key reference: ' + msg.CRM_Key__c, null, @@ -228,7 +229,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess */ private Person__c createPersonRecords(KafkaMessage__c message) { Person__c person = new Person__c(); - person = setTombstoneFlag(person, message); + //person = setTombstoneFlag(person, message); person.INT_LastUpdatedFromPDL__c = message.createdDate; //If tombstone and no payload, clear data for person except idents. @@ -237,12 +238,12 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess return person; } - emptyPersonFieldValues(person); + emptyPersonFieldValues(person); // why is this necessary? String decodedValue = KafkaMessageUtils.base64ULSafeDecode(message.CRM_Value__c).toString(); - KafkaPerson2 kafkaPerson = KafkaPerson2.parse(decodedValue); + KafkaPerson3 kafkaPerson = KafkaPerson3.parse(decodedValue); - validateListSizes(kafkaPerson); + //validateListSizes(kafkaPerson); person = mapFieldValues(person, kafkaPerson); return person; @@ -254,17 +255,13 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * @param kafkaPerson deserialized object representing a person from PDL * @return Person Account with initialized fields */ - private Person__c mapFieldValues(Person__c person, KafkaPerson2 kafkaPerson) { - if (kafkaPerson.identer != null && kafkaPerson.identer.isEmpty() == false) { - setIdents(kafkaPerson, person); - setName(kafkaPerson, person); - } else { - person.INT_ActorId__c = kafkaPerson.aktoerId; - if (kafkaPerson.folkeregisterId.size() > 0) { - person.Name = kafkaPerson.folkeregisterId[0]; - } - } + private Person__c mapFieldValues(Person__c person, KafkaPerson3 kafkaPerson) { + KafkaPerson3.HentIdenter hentIdenter = kafkaPerson.hentIdenter; + PDL_HentPerson hentPerson = kafkaPerson.hentPerson; + setIdents(person, hentIdenter, hentPerson); + setName(hentIdenter, person); + /* if (kafkaPerson.foedselsdato.size() > 0) { person.INT_DateOfBirth__c = kafkaPerson.foedselsdato[kafkaPerson.foedselsdato.size() - 1]; } @@ -362,6 +359,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess if (KafkaIntegrationCustomSetting.integrationUserId != null) { person.OwnerId = KafkaIntegrationCustomSetting.integrationUserId; } + */ return person; } @@ -657,14 +655,31 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } @TestVisible - private static void setIdents(KafkaPerson2 kafkaPerson, Person__c person) { - person.INT_NPID__c = Pdl_IdentUtility.getIdentsFromList(kafkaPerson.identer).npid; - setFolkeregisterIdents(kafkaPerson.folkeregisteridentifikator, person); + /** + * Sets ident based on HentIdenter, throws error if none is found. + */ + private static void setIdents( + Person__c person, + KafkaPerson3.HentIdenter hentIdenter, + PDL_HentPerson hentPerson + ) { + if (hentIdenter.identer != null && hentIdenter.identer.isEmpty() == false && + hentPerson.folkeregisteridentifikator != null && + hentPerson.folkeregisteridentifikator.isEmpty() == false) { + person.INT_NPID__c = Pdl_IdentUtility.getIdentsFromList(hentIdenter.identer).npid; + person.INT_fnr__c = Pdl_IdentUtility.getIdentsFromList(hentIdenter.identer).fnr; + setFolkeregisterIdents(person, hentPerson.folkeregisteridentifikator); + } else { + throw new PdlIdentException('Not able to set person idents from Kafka'); + } } + /** + * Sets idents based on PDL_HentPerson + */ private static void setFolkeregisterIdents( - PDL_FolkeregisterIdentifikator[] folkeregisterIdentifikator, - Person__c person + Person__c person, + PDL_FolkeregisterIdentifikator[] folkeregisterIdentifikator ) { for (PDL_FolkeregisterIdentifikator identifikator : folkeregisterIdentifikator) { if (String.isBlank(identifikator.identifikasjonsnummer)) { @@ -692,8 +707,8 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * if the list does not include valid idents - throwing exception */ @TestVisible - private static void setName(KafkaPerson2 kfkPerson, Person__c person) { - List identer = new List(kfkPerson.identer); + private static void setName(KafkaPerson3.HentIdenter hentIdenter, Person__c person) { + List identer = new List(hentIdenter.identer); String flkId; String npId; for (PDL_IdentInformasjon ident : identer) { @@ -841,10 +856,8 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } private void setMessageError(String errorMsg, KafkaMessage__c message) { - String decodedValue = KafkaMessageUtils.base64ULSafeDecode(message.CRM_Key__c).toString(); - Key key = (Key) System.JSON.deserialize(decodedValue, Key.class); - - if (existingActors != null && existingActors.contains(key.aktoer_id)) { + String aktoer_id = message.CRM_Key__c; + if (existingActors != null && existingActors.contains(aktoer_id)) { setMessageError(errorMsg, message, KafkaMessageService.STATUS_ERROR); } else { setMessageError(errorMsg, message, KafkaMessageService.STATUS_WARNING); diff --git a/force-app/pdl-handler/classes/KafkaPerson3.cls b/force-app/pdl-handler/classes/KafkaPerson3.cls new file mode 100644 index 00000000..92e8bc97 --- /dev/null +++ b/force-app/pdl-handler/classes/KafkaPerson3.cls @@ -0,0 +1,12 @@ +public with sharing class KafkaPerson3 { + public PDL_HentPerson hentPerson{get;} + public HentIdenter hentIdenter{get;} + + public class HentIdenter { + public PDL_IdentInformasjon[] identer{get;} + } + + public static KafkaPerson3 parse(String json) { + return (KafkaPerson3) System.JSON.deserialize(json, KafkaPerson3.class); + } +} diff --git a/force-app/pdl-handler/classes/KafkaPerson3.cls-meta.xml b/force-app/pdl-handler/classes/KafkaPerson3.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-handler/classes/KafkaPerson3.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + From e77783a72f0464dcc0d5eaf252da9f51cdab3e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 20 Feb 2024 15:28:04 +0100 Subject: [PATCH 007/159] be born --- .../classes/KafkaPdlPersondokumentHandler.cls | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 2ad4897c..7d9f532a 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -261,10 +261,13 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess setIdents(person, hentIdenter, hentPerson); setName(hentIdenter, person); - /* - if (kafkaPerson.foedselsdato.size() > 0) { - person.INT_DateOfBirth__c = kafkaPerson.foedselsdato[kafkaPerson.foedselsdato.size() - 1]; + if (hentPerson.foedsel != null && !hentPerson.foedsel.isEmpty() && + hentPerson.foedsel[hentPerson.foedsel.size() - 1].foedselsdato != null) { + DateTime dob = hentPerson.foedsel[hentPerson.foedsel.size() - 1].foedselsdato; // hack + person.INT_DateOfBirth__c = dob.format('yyyy-MM-dd'); } + + /* // Navn if (kafkaPerson.Navn.size() > 0) { person.INT_FirstName__c = stringValidator(kafkaPerson.Navn[kafkaPerson.Navn.size() - 1].fornavn); From 018c79232a7f2ee1bed78ba2a398ade134d67980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 16 Jan 2024 17:32:21 +0100 Subject: [PATCH 008/159] also allow being born in just a year --- .../classes/KafkaPdlPersondokumentHandler.cls | 12 ++++++++---- force-app/pdl-handler/classes/KafkaPerson3.cls | 3 +++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 7d9f532a..5b0ba9d7 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -261,10 +261,14 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess setIdents(person, hentIdenter, hentPerson); setName(hentIdenter, person); - if (hentPerson.foedsel != null && !hentPerson.foedsel.isEmpty() && - hentPerson.foedsel[hentPerson.foedsel.size() - 1].foedselsdato != null) { - DateTime dob = hentPerson.foedsel[hentPerson.foedsel.size() - 1].foedselsdato; // hack - person.INT_DateOfBirth__c = dob.format('yyyy-MM-dd'); + if (hentPerson.foedsel != null && !hentPerson.foedsel.isEmpty()) { + PDL_Foedsel foedsel = hentPerson.foedsel[hentPerson.foedsel.size() - 1]; + if (foedsel.foedselsdato != null) { + DateTime dob = foedsel.foedselsdato; // hack; Date lacks format + person.INT_DateOfBirth__c = dob.format('yyyy-MM-dd'); + } else if(foedsel.foedselsaar != null) { + person.INT_DateOfBirth__c = '' + foedsel.foedselsaar; + } } /* diff --git a/force-app/pdl-handler/classes/KafkaPerson3.cls b/force-app/pdl-handler/classes/KafkaPerson3.cls index 92e8bc97..a2c7af97 100644 --- a/force-app/pdl-handler/classes/KafkaPerson3.cls +++ b/force-app/pdl-handler/classes/KafkaPerson3.cls @@ -1,3 +1,6 @@ +/** + * Basically a deserializable PDL_Data + */ public with sharing class KafkaPerson3 { public PDL_HentPerson hentPerson{get;} public HentIdenter hentIdenter{get;} From 83edb5badca3c845f0bf5fec7c3ae2c46cf6785b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 15 Jan 2024 19:23:09 +0100 Subject: [PATCH 009/159] have name --- .../classes/KafkaPdlPersondokumentHandler.cls | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 5b0ba9d7..5ef0ccaf 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -250,17 +250,10 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * Transform and map fields from PDL data structure to Person__c SObject - * @param person New Person__c SObject record - * @param kafkaPerson deserialized object representing a person from PDL - * @return Person Account with initialized fields + * Set date (or year) of birth. + * Takes Date or Integer, sets String. */ - private Person__c mapFieldValues(Person__c person, KafkaPerson3 kafkaPerson) { - KafkaPerson3.HentIdenter hentIdenter = kafkaPerson.hentIdenter; - PDL_HentPerson hentPerson = kafkaPerson.hentPerson; - setIdents(person, hentIdenter, hentPerson); - setName(hentIdenter, person); - + private static void setDateOfBirth(Person__c person, PDL_HentPerson hentPerson) { if (hentPerson.foedsel != null && !hentPerson.foedsel.isEmpty()) { PDL_Foedsel foedsel = hentPerson.foedsel[hentPerson.foedsel.size() - 1]; if (foedsel.foedselsdato != null) { @@ -270,15 +263,30 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess person.INT_DateOfBirth__c = '' + foedsel.foedselsaar; } } + } + + /** + * Transforms and map fields to Person__c from KafkaPerson3 + * @param person New Person__c SObject record + * @param kafkaPerson deserialized object representing a PersonDokument + * @return Person Account with initialized fields + */ + private Person__c mapFieldValues(Person__c person, KafkaPerson3 kafkaPerson) { + KafkaPerson3.HentIdenter hentIdenter = kafkaPerson.hentIdenter; + PDL_HentPerson hentPerson = kafkaPerson.hentPerson; + setIdents(person, hentIdenter, hentPerson); + setName(person, hentIdenter); + setDateOfBirth(person, hentPerson); - /* // Navn - if (kafkaPerson.Navn.size() > 0) { - person.INT_FirstName__c = stringValidator(kafkaPerson.Navn[kafkaPerson.Navn.size() - 1].fornavn); - person.INT_MiddleName__c = stringValidator(kafkaPerson.Navn[kafkaPerson.Navn.size() - 1].mellomnavn); - person.INT_LastName__c = stringValidator(kafkaPerson.Navn[kafkaPerson.Navn.size() - 1].etternavn); + if (hentPerson.navn.size() > 0) { + PDL_Navn navn = hentPerson.navn[hentPerson.navn.size() - 1]; + person.INT_FirstName__c = stringValidator(navn.fornavn); + person.INT_MiddleName__c = stringValidator(navn.mellomnavn); + person.INT_LastName__c = stringValidator(navn.etternavn); } + /* // folkeregisterpersonstatus if (kafkaPerson.folkeregisterpersonstatus.size() > 0) { person.INT_LegalStatus__c = kafkaPerson.folkeregisterpersonstatus[0]; @@ -714,7 +722,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * if the list does not include valid idents - throwing exception */ @TestVisible - private static void setName(KafkaPerson3.HentIdenter hentIdenter, Person__c person) { + private static void setName(Person__c person, KafkaPerson3.HentIdenter hentIdenter) { List identer = new List(hentIdenter.identer); String flkId; String npId; From 41797c91dae96b4afc1a776f37b52b6f4407e1fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 16 Jan 2024 18:14:10 +0100 Subject: [PATCH 010/159] set actor id and pass aforementioned test --- force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 1 + 1 file changed, 1 insertion(+) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 5ef0ccaf..cc0c9665 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -230,6 +230,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess private Person__c createPersonRecords(KafkaMessage__c message) { Person__c person = new Person__c(); //person = setTombstoneFlag(person, message); + person.INT_ActorId__c = message.CRM_Key__c; // prev handled in setTombstoneFlag person.INT_LastUpdatedFromPDL__c = message.createdDate; //If tombstone and no payload, clear data for person except idents. From e957352edda5722c226047e72072875ed22667f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 16 Jan 2024 23:49:12 +0100 Subject: [PATCH 011/159] add empty document for testing, register handler --- dummy-data/kafkaMessages/KafkaMessages.json | 10 ++++++++ ...ndlerBinding.PDLPersonHandler3.md-meta.xml | 25 +++++++++++++++++++ ...nding.PdlGeografiskTilknytning.md-meta.xml | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PDLPersonHandler3.md-meta.xml diff --git a/dummy-data/kafkaMessages/KafkaMessages.json b/dummy-data/kafkaMessages/KafkaMessages.json index 077fe011..b55aa6ce 100644 --- a/dummy-data/kafkaMessages/KafkaMessages.json +++ b/dummy-data/kafkaMessages/KafkaMessages.json @@ -29,6 +29,16 @@ "CRM_Topic__c": "pdl.geografisktilknytning-v1", "CRM_Key__c": "2584233575802", "CRM_Value__c": "eyJpZGVudGVyIjpbIjI2OTEyMTIyNDA4MDAiLCIyNjA5NzIwOTE5NiJdLCJnZW9ncmFmaXNrVGlsa255dG5pbmciOnsiZ3RUeXBlIjoiS09NTVVORSIsImd0S29tbXVuZSI6IjQ2MTQiLCJndEJ5ZGVsIjpudWxsLCJndExhbmQiOm51bGwsInJlZ2VsIjoiMiJ9fQo=" + }, + { + "attributes": { + "type": "KafkaMessage__c", + "referenceId": "KafkaMessage__cRef4" + }, + "CRM_Status__c": "Pending", + "CRM_Topic__c": "pdl.pdl-persondokument-tagged-v1", + "CRM_Key__c": "2691212240801", + "CRM_Value__c": null } ] } diff --git a/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PDLPersonHandler3.md-meta.xml b/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PDLPersonHandler3.md-meta.xml new file mode 100644 index 00000000..6b15f2ef --- /dev/null +++ b/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PDLPersonHandler3.md-meta.xml @@ -0,0 +1,25 @@ + + + + false + + ApexClass__c + KafkaPdlPersondokumentHandler + + + Description__c + + + + Priority__c + 20.0 + + + Topic__c + pdl.pdl-persondokument-tagged-v1 + + + ApexJobType__c + Batch Apex + + diff --git a/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlGeografiskTilknytning.md-meta.xml b/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlGeografiskTilknytning.md-meta.xml index 9edb12ba..54e0b078 100644 --- a/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlGeografiskTilknytning.md-meta.xml +++ b/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlGeografiskTilknytning.md-meta.xml @@ -4,7 +4,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" > - + false ApexClass__c From 498a674407ec6101a327154c81c80a53994d1f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 17 Jan 2024 15:18:43 +0100 Subject: [PATCH 012/159] POC tombstone handling --- .../classes/KafkaPdlPersondokumentHandler.cls | 28 +++++++++++-------- .../KafkaPdlPersondokumentHandlerTest.cls | 20 +++++++++++++ 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index cc0c9665..1e94316e 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -34,7 +34,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess //If we have a message where the created date is older than last updated, set it to error so that we can investigate it. //If we have a tombstone without a person in Salesforce, set it to processed. - //checkLastUpdatedAndTombStones(messages); + checkLastUpdatedAndTombStones(messages); // Errors are caught and saved on each KafkaMessage record for (KafkaMessage__c msg : messages) { @@ -118,8 +118,11 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * Validates that the Kafka Message is not older than the last PDL Update on the Person - * If a new person is a tombstone, do not import it + * Validates that the Kafka Message is not older than the last PDL Update on + * the Person. + * If a new person is a tombstone, do not import it. + * Tombstones are not explicitly named in the message key, but are described + * by an empty message value. * @param messages Set of Kafka Messages in scope * @return Deduplicated set of Kafka Message */ @@ -135,13 +138,14 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess Set split = new Set(); for (KafkaMessage__c msg : messages) { - Key k = getKeyFromBase64(msg.CRM_Key__c); - //Lists of key values wich match order of kafka messages - idList.add(k.aktoer_id); - tombList.add(k.tombstone); - //A Set of idents with tombstones from kafka messages - if (k.tombstone == true) { - tombSet.add(k.aktoer_id); + String actorId = msg.CRM_Key__c; + Boolean isTombstone = msg.CRM_Value__c == null; + // Lists of key values wich match order of kafka messages + idList.add(actorId); + tombList.add(isTombstone); + // A Set of idents with tombstones from kafka messages + if (isTombstone) { + tombSet.add(actorId); } } for (Person__c p : [ @@ -223,7 +227,9 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * Orchestrate deserialization, transformation, and Person__c creation for each KafkaMessage + * Orchestrate deserialization, transformation, and Person__c creation for + * each KafkaMessage + * Quite similar to PDL_API_Query.makePersonFromResponse. * @param message integration record inserted by the integration user * @return Initialized Person Account ready for DML */ diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 533542f9..4dd1f653 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -356,4 +356,24 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual(1, pl.size(), 'Expected one person inserted.'); Test.stopTest(); } + + @isTest + static void testTombstoneIsNotInserted() { + List kafkaMessages = new List(); + kafkaMessages.add( + new KafkaMessage__c( + CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Key__c = '2594819806564', + CRM_Value__c = null, + CRM_Status__c = KafkaMessageService.STATUS_PENDING + ) + ); + Test.startTest(); + Integer numPersonsBefore = [select id from person__c].size(); + KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); + handler.processMessages(kafkaMessages); + Assert.areEqual(numPersonsBefore, [select id from person__c].size(), + 'Expected none inserted.'); + Test.stopTest(); + } } From f3504d07901980fbb4b725f554136279bb3d819e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 22 Jan 2024 13:56:00 +0100 Subject: [PATCH 013/159] clarify NPID and other idents --- .../pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 1e94316e..d2a28d30 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -725,8 +725,10 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } } /** - * Sets the Name field to one of valid idents with priority: FOLKEREGISTERIDENT, NPID, AKTORID - * if the list does not include valid idents - throwing exception + * Sets the Name field to a valid identifier. + * Priority: FOLKEREGISTERIDENT, NPID + * See https://confluence.adeo.no/display/PDL/NPID+-+NAVs+personidentifikator + * If the list does not include valid idents, throws an exception. */ @TestVisible private static void setName(Person__c person, KafkaPerson3.HentIdenter hentIdenter) { From 529f1e6c868d3d62a06484d180c2946c3f2a3fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 22 Jan 2024 14:18:14 +0100 Subject: [PATCH 014/159] make setFolkeregisterIdents a bit more readable --- .../classes/KafkaPdlPersondokumentHandler.cls | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index d2a28d30..850178ea 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -696,34 +696,33 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } } + private static void assignFnrIfAppropriate(Person__c p, PDL_FolkeregisterIdentifikator id) { + if (id.type == PDL_IdentType.FNR && !id.metadata.historisk && id.status == PDL_IdentStatus.I_BRUK) { + p.INT_fnr__c = id.identifikasjonsnummer; + } + } + + private static void assignDnrIfAppropriate(Person__c p, PDL_FolkeregisterIdentifikator id) { + if (id.type == PDL_IdentType.DNR && String.isBlank(p.INT_dnr__c) || !id.metadata.historisk) { + p.INT_dnr__c = id.identifikasjonsnummer; + } + } + /** - * Sets idents based on PDL_HentPerson + * Sets idents. Based on the same function in PDL_HentPerson. */ private static void setFolkeregisterIdents( Person__c person, - PDL_FolkeregisterIdentifikator[] folkeregisterIdentifikator + PDL_FolkeregisterIdentifikator[] identifiers ) { - for (PDL_FolkeregisterIdentifikator identifikator : folkeregisterIdentifikator) { - if (String.isBlank(identifikator.identifikasjonsnummer)) { - continue; - } - - switch on identifikator.type { - when DNR { - if (String.isBlank(person.INT_dnr__c) || identifikator.metadata.historisk == false) { - person.INT_dnr__c = identifikator.identifikasjonsnummer; - } - continue; - } - when FNR { - if (identifikator.metadata.historisk == false && identifikator.status == PDL_IdentStatus.I_BRUK) { - person.INT_fnr__c = identifikator.identifikasjonsnummer; - } - continue; - } + for (PDL_FolkeregisterIdentifikator id : identifiers) { + if (String.isNotBlank(id.identifikasjonsnummer)) { // when is this blank? + assignFnrIfAppropriate(person, id); + assignDnrIfAppropriate(person, id); } } } + /** * Sets the Name field to a valid identifier. * Priority: FOLKEREGISTERIDENT, NPID From 10864a5ff25cb779abb219f341d67c44f5af0431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 22 Jan 2024 16:59:44 +0100 Subject: [PATCH 015/159] add tombstone test, probably false negative --- .../classes/KafkaPDLHandler2Test.cls | 2 +- .../KafkaPdlPersondokumentHandlerTest.cls | 50 ++++++++++++++++--- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPDLHandler2Test.cls b/force-app/pdl-handler/classes/KafkaPDLHandler2Test.cls index 4c3830cf..7371b56d 100644 --- a/force-app/pdl-handler/classes/KafkaPDLHandler2Test.cls +++ b/force-app/pdl-handler/classes/KafkaPDLHandler2Test.cls @@ -142,7 +142,7 @@ private with sharing class KafkaPDLHandler2Test { kPerson.identer[1].gruppe = PDL_IdentGruppe.NPID; kPerson.identer.add(new PDL_IdentInformasjon()); - kPerson.identer[2].ident = '52345678901'; + kPerson.identer[2].ident = '5234567890169'; kPerson.identer[2].historisk = false; kPerson.identer[2].gruppe = PDL_IdentGruppe.AKTORID; diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 4dd1f653..c5c91ba8 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1,16 +1,17 @@ @IsTest private with sharing class KafkaPdlPersondokumentHandlerTest { + @TestSetup static void makeData() { // record for setting correct Country from Country ISO code List commonCodes = new List(); - Common_Code__c ccIND = new Common_Code__c(); - ccIND.Name = 'India'; - ccIND.CRM_Code_Set__c = 'Landkoder'; - ccIND.CRM_Code__c = 'IND'; - ccIND.CRM_Active__c = true; - commonCodes.add(ccIND); + Common_Code__c ccBEL = new Common_Code__c(); + ccBEL.Name = 'BELGIA'; + ccBEL.CRM_Code_Set__c = 'Landkoder'; + ccBEL.CRM_Code__c = 'BEL'; + ccBEL.CRM_Active__c = true; + commonCodes.add(ccBEL); Common_Code__c ccNOR = new Common_Code__c(); ccNOR.Name = 'Norge'; @@ -376,4 +377,41 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { 'Expected none inserted.'); Test.stopTest(); } + + /******************************************* + * TESTS FOR checkLastUpdatedAndTombStones * + *******************************************/ + + //SCENARIO: + // A Person exists in Salesforce and we try to process a KafkaMessage__c where the CreatedDate is older than the Person LastModifiedDate + // KafkaMessage__c.CRM_Status__c should be set to error + @IsTest + static void checkLastUpdatedAndTombStonesOlderMessages() { + Person__c person1 = new Person__c(); + person1.INT_ActorId__c = '1000012345678'; + person1.Name = '20000000000'; + person1.INT_fnr__c = '20000000000'; + person1.INT_LastUpdatedFromPDL__c = Datetime.now(); + insert person1; + String createdDate = Datetime.now().addDays(-2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + KafkaMessage__c msg = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate + + '"}', + KafkaMessage__c.class + ); + msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg.CRM_Key__c = '1000012345678'; + // CRM_Value__c is null + Test.startTest(); + new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg }); + Test.stopTest(); + System.assertEquals( + KafkaMessageService.STATUS_WARNING, + msg.CRM_Status__c, + 'Expected the status to be set to warning' + ); + } + } From cea418520e30909a16cbc6fdb7f4b98f3d850b33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 23 Jan 2024 11:46:35 +0100 Subject: [PATCH 016/159] add more tombstone tests, 3 fail --- .../KafkaPdlPersondokumentHandlerTest.cls | 247 +++++++++++++++++- 1 file changed, 240 insertions(+), 7 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index c5c91ba8..8f7a4e2b 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -396,9 +396,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { String createdDate = Datetime.now().addDays(-2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); KafkaMessage__c msg = (KafkaMessage__c) JSON.deserializeStrict( '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + - createdDate + - '"}', - KafkaMessage__c.class + createdDate + '"}', KafkaMessage__c.class ); msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; @@ -407,11 +405,246 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Test.startTest(); new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg }); Test.stopTest(); - System.assertEquals( - KafkaMessageService.STATUS_WARNING, - msg.CRM_Status__c, - 'Expected the status to be set to warning' + Assert.areEqual(KafkaMessageService.STATUS_WARNING, msg.CRM_Status__c, + 'Expected the status to be set to warning'); + } + + //SCENARIO: + // A Person exists in Salesforce and we try to process a KafkaMessage__c where the persons INT_LastUpdatedFromPDL__c is empty + // KafkaMessage__c.CRM_Status__c should not be updated + @IsTest + static void checkLastUpdatedAndTombStonesNewMessagesNoLastUpdated() { + Person__c person1 = new Person__c(); + person1.INT_ActorId__c = '1000012345678'; + person1.Name = '20000000000'; + person1.INT_fnr__c = '20000000000'; + person1.INT_LastUpdatedFromPDL__c = null; + insert person1; + String createdDate = Datetime.now().addDays(2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + KafkaMessage__c msg = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate + '"}', KafkaMessage__c.class + ); + msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg.CRM_Key__c = '1000012345678'; + // CRM_Value__c is null + Test.startTest(); + new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg }); + Test.stopTest(); + Assert.areEqual(KafkaMessageService.STATUS_PENDING, msg.CRM_Status__c, + 'Expected the status to be the same'); + } + + //SCENARIO: + // A Person exists in Salesforce and we try to process a KafkaMessage__c where the CreatedDate is after than the Person INT_LastUpdatedFromPDL__c + // KafkaMessage__c.CRM_Status__c should not be updated + @IsTest + static void checkLastUpdatedAndTombStonesNewMessages() { + Person__c person1 = new Person__c(); + person1.INT_ActorId__c = '1000012345678'; + person1.Name = '20000000000'; + person1.INT_fnr__c = '20000000000'; + person1.INT_LastUpdatedFromPDL__c = Datetime.now(); + insert person1; + String createdDate = Datetime.now().addDays(2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + KafkaMessage__c msg = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate + '"}', KafkaMessage__c.class + ); + msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg.CRM_Key__c = '1000012345678'; + Test.startTest(); + new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg }); + Test.stopTest(); + Assert.areEqual(KafkaMessageService.STATUS_PENDING, msg.CRM_Status__c, + 'Expected the status to be the same'); + } + + //SCENARIO: + // We try to process a KafkaMessage__c where we don't have any matching person in Salesforce + // KafkaMessage__c.CRM_Status__c should not be updated + @IsTest + static void checkLastUpdatedAndTombStonesBrandNewMessages() { + String createdDate = Datetime.now().addDays(2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + KafkaMessage__c msg = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate + '"}', KafkaMessage__c.class + ); + msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg.CRM_Key__c = '1000012345678'; + Test.startTest(); + new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg }); + Test.stopTest(); + Assert.areEqual(KafkaMessageService.STATUS_PENDING, msg.CRM_Status__c, + 'Expected the status to be the same'); + } + + //SCENARIO: + // We try to process several KafkaMessage__c where they all have the same key and matches a Person in Salesforce + // KafkaMessage__c.CRM_Status__c should be set to processec on only the oldest + @IsTest + static void checkLastUpdatedAndTombStonesNewDuplicateMessages() { + Person__c person1 = new Person__c(); + person1.INT_ActorId__c = '1000012345678'; + person1.Name = '20000000000'; + person1.INT_fnr__c = '20000000000'; + person1.INT_LastUpdatedFromPDL__c = Datetime.now(); + insert person1; + String createdDate1 = Datetime.now().addDays(2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + String createdDate2 = Datetime.now().addDays(3).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + String createdDate3 = Datetime.now().addDays(1).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + String createdDate4 = Datetime.now().addDays(-2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + KafkaMessage__c msg1 = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate1 + '"}', KafkaMessage__c.class + ); + msg1.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg1.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg1.CRM_Key__c = '1000012345678'; + // The newest + KafkaMessage__c msg2 = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate2 + '"}', KafkaMessage__c.class + ); + msg2.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg2.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg2.CRM_Key__c = '1000012345678'; + KafkaMessage__c msg3 = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate3 + '"}', KafkaMessage__c.class + ); + msg3.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg3.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg3.CRM_Key__c = '1000012345678'; + KafkaMessage__c msg4 = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate4 + '"}', KafkaMessage__c.class + ); + msg4.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg4.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg4.CRM_Key__c = '1000012345678'; + Test.startTest(); + new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg1, msg2, msg3, msg4 }); + Test.stopTest(); + Assert.areEqual(KafkaMessageService.STATUS_PENDING, msg1.CRM_Status__c, + 'Expected the status to be processed'); + Assert.areEqual(KafkaMessageService.STATUS_PENDING, msg2.CRM_Status__c, + 'Expected the status to be the same'); + Assert.areEqual(KafkaMessageService.STATUS_PENDING, msg3.CRM_Status__c, + 'Expected the status to be processed'); + Assert.areEqual(KafkaMessageService.STATUS_WARNING, msg4.CRM_Status__c, + 'Expected the status to be warning'); + } + + //SCENARIO: + // We try to process two several KafkaMessage__c where they all have the same actorId that matches a Person in Salesforce, but one is a tombstone + // Both KafkaMessage__c should be processed + @IsTest + static void checkLastUpdatedAndTombStonesDuplicateMessagesWithTombstone() { + Person__c person1 = new Person__c(); + person1.INT_ActorId__c = '1000012345678'; + person1.Name = '20000000000'; + person1.INT_fnr__c = '20000000000'; + person1.INT_LastUpdatedFromPDL__c = Datetime.now(); + insert person1; + String createdDate1 = Datetime.now().addDays(1).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + String createdDate2 = Datetime.now().addDays(2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + KafkaMessage__c msg1 = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate1 + '"}', KafkaMessage__c.class + ); + msg1.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg1.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg1.CRM_Key__c = '1000012345678'; + // The newest + KafkaMessage__c msg2 = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate2 + '"}', KafkaMessage__c.class + ); + msg2.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg2.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg2.CRM_Key__c = '1000012345678'; + Test.startTest(); + new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg1, msg2 }); + Test.stopTest(); + Assert.areEqual(KafkaMessageService.STATUS_WARNING, msg1.CRM_Status__c, + 'Expected the status to be warning'); + Assert.areEqual(KafkaMessageService.STATUS_PENDING, msg2.CRM_Status__c, + 'Expected the status to be pending'); + } + + //SCENARIO: + // We try process a KafkaMessage__c where we dont have a match a Person in Salesforce, but one is a tombstone + // KafkaMessage__c.CRM_Status__c should be set to processed + @IsTest + static void checkLastUpdatedAndTombStonesBrandNewMessagesWithTombstone() { + String createdDate1 = Datetime.now().addDays(1).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); + KafkaMessage__c msg1 = (KafkaMessage__c) JSON.deserializeStrict( + '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + + createdDate1 + '"}', KafkaMessage__c.class + ); + msg1.CRM_Status__c = KafkaMessageService.STATUS_PENDING; + msg1.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg1.CRM_Key__c = '1000012345678'; + Test.startTest(); + new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg1 }); + Test.stopTest(); + Assert.areEqual(KafkaMessageService.STATUS_PROCESSED, msg1.CRM_Status__c, + 'Expected the status to be processed' + ); + } + + //SCENARIO: + // We try process a KafkaMessage__c where we have a match a Person in Salesforce, the message is a tombstone and the value is null + // Person should get a tombstone + @IsTest + static void processTombstoneTest() { + insert new Person__c( + Name = '12345678901', + INT_fnr__c = '12345678901', + INT_ActorId__c = '1000012345678', + INT_FirstName__c = 'FNAME', + INT_LastName__c = 'LNAME' + ); + List kafkaMessages = new List(); + kafkaMessages.add( + new KafkaMessage__c( + CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Key__c = '1000012345678', + CRM_Value__c = null + ) + ); + // Verify that we have only one Account + Assert.areEqual(1, [SELECT COUNT() FROM Person__c]); + // Act + Test.startTest(); + insert kafkaMessages; + System.debug([SELECT Id, CRM_Topic__c, CRM_Key__c, CRM_ErrorMessage__c FROM KafkaMessage__c]); + AsyncRequestSchedulable.enqueueAsyncJobs(); + Test.stopTest(); + System.debug([SELECT Id, CRM_Topic__c, CRM_Key__c, CRM_ErrorMessage__c FROM KafkaMessage__c]); + // Assert that 1 Person Account has been inserted + Assert.areEqual(1, [SELECT COUNT() FROM Person__c]); + // Assert that all Kafka Message records have been marked as processed + Assert.areEqual( + 1, + [SELECT COUNT() FROM KafkaMessage__c WHERE CRM_Status__c = :KafkaMessageService.STATUS_PROCESSED] ); + Person__c p = [ + SELECT Id, INT_ActorId__c, INT_fnr__c, Name, INT_IsHasTombstone__c, INT_FirstName__c, INT_LastName__c + FROM Person__c + LIMIT 1 + ]; + // Assert that only tombstone and id fields has values + Assert.areEqual('1000012345678', p.INT_ActorId__c, 'ActorId'); + Assert.areEqual('12345678901', p.INT_fnr__c, 'fnr'); + Assert.areEqual('12345678901', p.Name, 'Name'); + Assert.areEqual(true, p.INT_IsHasTombstone__c, 'Tombstone'); + Assert.areEqual(null, p.INT_FirstName__c, 'Firstname'); + Assert.areEqual(null, p.INT_LastName__c, 'Lastname'); } } From 995b455e274eac380bdc2f519c6ff07b4375a17c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 23 Jan 2024 13:11:58 +0100 Subject: [PATCH 017/159] minor --- .../KafkaPdlPersondokumentHandlerTest.cls | 64 ++++++++++++------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 8f7a4e2b..8d546ab5 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -382,9 +382,11 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { * TESTS FOR checkLastUpdatedAndTombStones * *******************************************/ - //SCENARIO: - // A Person exists in Salesforce and we try to process a KafkaMessage__c where the CreatedDate is older than the Person LastModifiedDate - // KafkaMessage__c.CRM_Status__c should be set to error + /* SCENARIO: + * A Person exists in Salesforce and we try to process a KafkaMessage__c + * where the CreatedDate is older than the Person LastModifiedDate + * KafkaMessage__c.CRM_Status__c should be set to error + */ @IsTest static void checkLastUpdatedAndTombStonesOlderMessages() { Person__c person1 = new Person__c(); @@ -409,9 +411,11 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { 'Expected the status to be set to warning'); } - //SCENARIO: - // A Person exists in Salesforce and we try to process a KafkaMessage__c where the persons INT_LastUpdatedFromPDL__c is empty - // KafkaMessage__c.CRM_Status__c should not be updated + /* SCENARIO: + * A Person exists in Salesforce and we try to process a KafkaMessage__c + * where the persons INT_LastUpdatedFromPDL__c is empty + * KafkaMessage__c.CRM_Status__c should not be updated + */ @IsTest static void checkLastUpdatedAndTombStonesNewMessagesNoLastUpdated() { Person__c person1 = new Person__c(); @@ -436,9 +440,11 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { 'Expected the status to be the same'); } - //SCENARIO: - // A Person exists in Salesforce and we try to process a KafkaMessage__c where the CreatedDate is after than the Person INT_LastUpdatedFromPDL__c - // KafkaMessage__c.CRM_Status__c should not be updated + /* SCENARIO: + * A Person exists in Salesforce and we try to process a KafkaMessage__c + * where the CreatedDate is after than the Person INT_LastUpdatedFromPDL__c + * KafkaMessage__c.CRM_Status__c should not be updated + */ @IsTest static void checkLastUpdatedAndTombStonesNewMessages() { Person__c person1 = new Person__c(); @@ -462,9 +468,11 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { 'Expected the status to be the same'); } - //SCENARIO: - // We try to process a KafkaMessage__c where we don't have any matching person in Salesforce - // KafkaMessage__c.CRM_Status__c should not be updated + /* SCENARIO: + * We try to process a KafkaMessage__c where we don't have any matching + * person in Salesforce + * KafkaMessage__c.CRM_Status__c should not be updated + */ @IsTest static void checkLastUpdatedAndTombStonesBrandNewMessages() { String createdDate = Datetime.now().addDays(2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); @@ -482,9 +490,11 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { 'Expected the status to be the same'); } - //SCENARIO: - // We try to process several KafkaMessage__c where they all have the same key and matches a Person in Salesforce - // KafkaMessage__c.CRM_Status__c should be set to processec on only the oldest + /* SCENARIO: + * We try to process several KafkaMessage__c where they all have the same + * key and matches a Person in Salesforce + * KafkaMessage__c.CRM_Status__c should be set to processec on only the oldest + */ @IsTest static void checkLastUpdatedAndTombStonesNewDuplicateMessages() { Person__c person1 = new Person__c(); @@ -539,9 +549,11 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { 'Expected the status to be warning'); } - //SCENARIO: - // We try to process two several KafkaMessage__c where they all have the same actorId that matches a Person in Salesforce, but one is a tombstone - // Both KafkaMessage__c should be processed + /* SCENARIO: + * We try to process two several KafkaMessage__c where they all have the + * same actorId that matches a Person in Salesforce, but one is a tombstone + * Both KafkaMessage__c should be processed + */ @IsTest static void checkLastUpdatedAndTombStonesDuplicateMessagesWithTombstone() { Person__c person1 = new Person__c(); @@ -576,9 +588,11 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { 'Expected the status to be pending'); } - //SCENARIO: - // We try process a KafkaMessage__c where we dont have a match a Person in Salesforce, but one is a tombstone - // KafkaMessage__c.CRM_Status__c should be set to processed + /* SCENARIO: + * We try process a KafkaMessage__c where we dont have a match a Person in + * Salesforce, but one is a tombstone + * KafkaMessage__c.CRM_Status__c should be set to processed + */ @IsTest static void checkLastUpdatedAndTombStonesBrandNewMessagesWithTombstone() { String createdDate1 = Datetime.now().addDays(1).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); @@ -597,9 +611,11 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { ); } - //SCENARIO: - // We try process a KafkaMessage__c where we have a match a Person in Salesforce, the message is a tombstone and the value is null - // Person should get a tombstone + /* SCENARIO: + * We try process a KafkaMessage__c where we have a match a Person in + * Salesforce, the message is a tombstone and the value is null + * Person should get a tombstone + */ @IsTest static void processTombstoneTest() { insert new Person__c( From 5c956bf93a61931b22bd486e42ad946e7fb0d894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 23 Jan 2024 17:56:24 +0100 Subject: [PATCH 018/159] these weren't meant to be tombstones pass every tombstone sanity check, only processTombstoneTest fails --- .../KafkaPdlPersondokumentHandlerTest.cls | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 8d546ab5..d31bf768 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -403,7 +403,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; msg.CRM_Key__c = '1000012345678'; - // CRM_Value__c is null + msg.CRM_Value__c = 'e30K'; // empty dict: nonnull, so tombstone is false Test.startTest(); new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg }); Test.stopTest(); @@ -432,7 +432,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; msg.CRM_Key__c = '1000012345678'; - // CRM_Value__c is null + msg.CRM_Value__c = 'e30K'; // {} Test.startTest(); new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg }); Test.stopTest(); @@ -461,6 +461,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; msg.CRM_Key__c = '1000012345678'; + msg.CRM_Value__c = 'e30K'; // {} Test.startTest(); new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg }); Test.stopTest(); @@ -483,6 +484,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; msg.CRM_Key__c = '1000012345678'; + msg.CRM_Value__c = 'e30K'; // {} Test.startTest(); new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg }); Test.stopTest(); @@ -514,6 +516,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { msg1.CRM_Status__c = KafkaMessageService.STATUS_PENDING; msg1.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; msg1.CRM_Key__c = '1000012345678'; + msg1.CRM_Value__c = 'e30K'; // {} // The newest KafkaMessage__c msg2 = (KafkaMessage__c) JSON.deserializeStrict( '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + @@ -522,6 +525,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { msg2.CRM_Status__c = KafkaMessageService.STATUS_PENDING; msg2.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; msg2.CRM_Key__c = '1000012345678'; + msg2.CRM_Value__c = 'e30K'; // {} KafkaMessage__c msg3 = (KafkaMessage__c) JSON.deserializeStrict( '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + createdDate3 + '"}', KafkaMessage__c.class @@ -529,6 +533,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { msg3.CRM_Status__c = KafkaMessageService.STATUS_PENDING; msg3.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; msg3.CRM_Key__c = '1000012345678'; + msg3.CRM_Value__c = 'e30K'; // {} KafkaMessage__c msg4 = (KafkaMessage__c) JSON.deserializeStrict( '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + createdDate4 + '"}', KafkaMessage__c.class @@ -536,6 +541,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { msg4.CRM_Status__c = KafkaMessageService.STATUS_PENDING; msg4.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; msg4.CRM_Key__c = '1000012345678'; + msg4.CRM_Value__c = 'e30K'; // {} Test.startTest(); new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg1, msg2, msg3, msg4 }); Test.stopTest(); @@ -571,6 +577,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { msg1.CRM_Status__c = KafkaMessageService.STATUS_PENDING; msg1.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; msg1.CRM_Key__c = '1000012345678'; + msg1.CRM_Value__c = 'e30K'; // {} // The newest KafkaMessage__c msg2 = (KafkaMessage__c) JSON.deserializeStrict( '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + @@ -579,13 +586,14 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { msg2.CRM_Status__c = KafkaMessageService.STATUS_PENDING; msg2.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; msg2.CRM_Key__c = '1000012345678'; + // CRM_Value__c is null Test.startTest(); new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg1, msg2 }); Test.stopTest(); Assert.areEqual(KafkaMessageService.STATUS_WARNING, msg1.CRM_Status__c, - 'Expected the status to be warning'); + 'Expected msg1 status to be warning'); Assert.areEqual(KafkaMessageService.STATUS_PENDING, msg2.CRM_Status__c, - 'Expected the status to be pending'); + 'Expected msg2 status to be pending'); } /* SCENARIO: @@ -603,6 +611,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { msg1.CRM_Status__c = KafkaMessageService.STATUS_PENDING; msg1.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; msg1.CRM_Key__c = '1000012345678'; + // CRM_Value__c is null Test.startTest(); new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg1 }); Test.stopTest(); From 16c94926817ad8ba9b401e496ddc67392aa21df2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 24 Jan 2024 10:27:09 +0100 Subject: [PATCH 019/159] simple tombstone check --- .../classes/KafkaPdlPersondokumentHandler.cls | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 850178ea..eb4bc858 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -234,10 +234,11 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * @return Initialized Person Account ready for DML */ private Person__c createPersonRecords(KafkaMessage__c message) { - Person__c person = new Person__c(); - //person = setTombstoneFlag(person, message); - person.INT_ActorId__c = message.CRM_Key__c; // prev handled in setTombstoneFlag - person.INT_LastUpdatedFromPDL__c = message.createdDate; + Person__c person = new Person__c( + INT_IsHasTombstone__c = String.isBlank(message.CRM_Value__c), + INT_ActorId__c = message.CRM_Key__c, + INT_LastUpdatedFromPDL__c = message.createdDate + ); //If tombstone and no payload, clear data for person except idents. if (true == person.INT_IsHasTombstone__c && String.isBlank(message.CRM_Value__c)) { @@ -385,14 +386,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess return person; } - private Person__c setTombstoneFlag(Person__c person, KafkaMessage__c message) { - String decodedValue = KafkaMessageUtils.base64ULSafeDecode(message.CRM_Key__c).toString(); - Key key = (Key) System.JSON.deserialize(decodedValue, Key.class); - person.INT_IsHasTombstone__c = key.tombstone; - person.INT_ActorId__c = key.aktoer_id; - return person; - } - @TestVisible private void setAddress(Person__c person, KafkaPerson2 kafkaPerson) { if (ADR_BESKYTTELSES_GRADERING.get(person.INT_Confidential__c) <= 2) { From 08446a9f8309ed715df339d67255f802bf130c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 26 Jan 2024 15:42:47 +0100 Subject: [PATCH 020/159] add setName test, create person, set status & more --- .../classes/PDL_Adressebeskyttelse.cls | 1 + .../pdl-apexTypes/classes/PDL_HentPerson.cls | 3 +- .../classes/PDL_Oppholdsadresse.cls | 2 +- .../KafkaPdlPersondokumentHandlerTest.cls | 78 +++++++++++++++++++ 4 files changed, 81 insertions(+), 3 deletions(-) diff --git a/force-app/pdl-apexTypes/classes/PDL_Adressebeskyttelse.cls b/force-app/pdl-apexTypes/classes/PDL_Adressebeskyttelse.cls index 77927a4c..52c72ce1 100644 --- a/force-app/pdl-apexTypes/classes/PDL_Adressebeskyttelse.cls +++ b/force-app/pdl-apexTypes/classes/PDL_Adressebeskyttelse.cls @@ -1,5 +1,6 @@ public with sharing class PDL_Adressebeskyttelse { + @TestVisible public PDL_AdressebeskyttelseGradering gradering{ get;} public PDL_Folkeregistermetadata folkeregistermetadata{ get;} public PDL_Metadata metadata{ get;} diff --git a/force-app/pdl-apexTypes/classes/PDL_HentPerson.cls b/force-app/pdl-apexTypes/classes/PDL_HentPerson.cls index ba8276e3..f0f94e54 100644 --- a/force-app/pdl-apexTypes/classes/PDL_HentPerson.cls +++ b/force-app/pdl-apexTypes/classes/PDL_HentPerson.cls @@ -1,5 +1,5 @@ public with sharing class PDL_HentPerson { - + public PDL_Adressebeskyttelse[] adressebeskyttelse{ get;} public PDL_Bostedsadresse[] bostedsadresse{ get;} public PDL_DeltBosted[] deltBosted{ get;} @@ -30,6 +30,5 @@ public with sharing class PDL_HentPerson { public PDL_VergemaalEllerFremtidsfullmakt[] vergemaalEllerFremtidsfullmakt{ get;} public PDL_HentPerson() { - } } diff --git a/force-app/pdl-apexTypes/classes/PDL_Oppholdsadresse.cls b/force-app/pdl-apexTypes/classes/PDL_Oppholdsadresse.cls index 7f77ff2b..ee5e2931 100644 --- a/force-app/pdl-apexTypes/classes/PDL_Oppholdsadresse.cls +++ b/force-app/pdl-apexTypes/classes/PDL_Oppholdsadresse.cls @@ -1,5 +1,5 @@ public with sharing class PDL_Oppholdsadresse { - + public Datetime gyldigFraOgMed{ get;} public Datetime gyldigTilOgMed{ get;} public String coAdressenavn{ get;} diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index d31bf768..9566f12e 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -23,6 +23,52 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { insert commonCodes; } + private static KafkaPerson3 createBaseKafkaPerson(String actorId) { + KafkaPerson3 kp = new KafkaPerson3(); + //kp.hentIdenter.identer = new List(); + //kp.hentPerson.folkeregisteridentifikator = new List(); + //kp.hentPerson.foedselsdato = new List(); + //kp.hentPerson.folkeregisterpersonstatus = new List(); + //kp.hentPerson.navn = new List(); + //kp.hentPerson.bostedsadresse = new KafkaPerson3.Adresser(); + //kp.hentPerson.bostedsadresse.vegadresse = new List(); + //kp.hentPerson.bostedsadresse.matrikkeladresse = new List(); + //kp.hentPerson.bostedsadresse.utenlandskAdresse = new List(); + //kp.hentPerson.bostedsadresse.ukjentBosted = new List(); + //kp.hentPerson.oppholdsadresse = new KafkaPerson3.Adresser(); + //kp.hentPerson.oppholdsadresse.vegadresse = new List(); + //kp.hentPerson.oppholdsadresse.matrikkeladresse = new List(); + //kp.hentPerson.oppholdsadresse.utenlandskAdresse = new List(); + //kp.hentPerson.oppholdsadresse.ukjentBosted = new List(); + //kp.hentPerson.innflyttingTilNorge = new List(); + //kp.hentPerson.utflyttingFraNorge = new List(); + //kp.hentPerson.adressebeskyttelse = new List(); + //kp.hentPerson.kommunenummerFraGt = ''; + //kp.hentPerson.bydelsnummerFraGt = ''; + //kp.hentPerson.sivilstand = new List(); + //kp.hentPerson.statsborgerskap = new List(); + //kp.hentPerson.kjoenn = new List(); + //kp.hentPerson.doedsfall = new List(); + //kp.hentPerson.telefonnummer = new List(); + //Default values + //Ident + kp.hentIdenter.identer.add(new PDL_IdentInformasjon()); + kp.hentIdenter.identer[0].gruppe = PDL_IdentGruppe.AKTORID; + kp.hentIdenter.identer[0].historisk = false; + kp.hentIdenter.identer[0].ident = actorId; + //Person status + PDL_Folkeregisterpersonstatus status; + status.status = 'bosatt'; + kp.hentPerson.folkeregisterpersonstatus.add(status); + //Navn + kp.hentPerson.navn.add(new PDL_Navn()); + kp.hentPerson.navn[0].etternavn = 'TRESTRESEN'; + PDL_Adressebeskyttelse beskyttelse = new PDL_Adressebeskyttelse(); + beskyttelse.gradering = PDL_AdressebeskyttelseGradering.UGRADERT; + kp.hentPerson.adressebeskyttelse.add(beskyttelse); + return kp; + } + @isTest static void testCreatePersonFromPersonDokument() { List kafkaMessages = new List(); @@ -672,4 +718,36 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual(null, p.INT_LastName__c, 'Lastname'); } + @IsTest + static void setNameException() { + KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); + kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); + kPerson.hentIdenter.identer[0].ident = '12345678901'; + kPerson.hentIdenter.identer[0].historisk = true; + kPerson.hentIdenter.identer[0].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); + kPerson.hentIdenter.identer[1].ident = '12345678911'; + kPerson.hentIdenter.identer[1].historisk = true; + kPerson.hentIdenter.identer[1].gruppe = PDL_IdentGruppe.NPID; + kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); + kPerson.hentIdenter.identer[2].ident = '5234567890169'; + kPerson.hentIdenter.identer[2].historisk = false; + kPerson.hentIdenter.identer[2].gruppe = PDL_IdentGruppe.AKTORID; + kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); + kPerson.hentIdenter.identer[3].ident = '12345678902'; + kPerson.hentIdenter.identer[3].historisk = true; + kPerson.hentIdenter.identer[3].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + Person__c person = new Person__c(); + Test.startTest(); + try { + KafkaPdlPersondokumentHandler.setName(person, kPerson.hentIdenter); + System.assert(false, 'No exception thrown'); + } catch (KafkaPdlPersondokumentHandler.PdlIdentException ex) { + System.assert(true); + } catch (Exception e) { + System.assert(false, 'Did not catch the correct exception'); + } + Test.stopTest(); + } + } From 1667c744a6b12ae43f2cc0032d4eccc3538cbd5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 29 Jan 2024 13:12:57 +0100 Subject: [PATCH 021/159] set everything else test now passes with correct exception --- .../pdl-apexTypes/classes/PDL_HentPerson.cls | 28 +++++++ .../KafkaPdlPersondokumentHandlerTest.cls | 83 ++++++++++--------- .../pdl-handler/classes/KafkaPerson3.cls | 3 + 3 files changed, 75 insertions(+), 39 deletions(-) diff --git a/force-app/pdl-apexTypes/classes/PDL_HentPerson.cls b/force-app/pdl-apexTypes/classes/PDL_HentPerson.cls index f0f94e54..d1030a68 100644 --- a/force-app/pdl-apexTypes/classes/PDL_HentPerson.cls +++ b/force-app/pdl-apexTypes/classes/PDL_HentPerson.cls @@ -1,32 +1,60 @@ public with sharing class PDL_HentPerson { + @TestVisible public PDL_Adressebeskyttelse[] adressebeskyttelse{ get;} + @TestVisible public PDL_Bostedsadresse[] bostedsadresse{ get;} + @TestVisible public PDL_DeltBosted[] deltBosted{ get;} + @TestVisible public PDL_DoedfoedtBarn[] doedfoedtBarn{ get;} + @TestVisible public PDL_Doedsfall[] doedsfall{ get;} + @TestVisible public PDL_FalskIdentitet falskIdentitet{ get;} + @TestVisible public PDL_Foedsel[] foedsel{ get;} + @TestVisible public PDL_Folkeregisteridentifikator[] folkeregisteridentifikator{ get;} + @TestVisible public PDL_Folkeregisterpersonstatus[] folkeregisterpersonstatus{ get;} + @TestVisible public PDL_ForelderBarnRelasjon[] forelderBarnRelasjon{ get;} + @TestVisible public PDL_Foreldreansvar[] foreldreansvar{ get;} + @TestVisible public PDL_Fullmakt[] fullmakt{ get;} + @TestVisible public PDL_Identitetsgrunnlag[] identitetsgrunnlag{ get;} + @TestVisible public PDL_Kjoenn[] kjoenn{ get;} + @TestVisible public PDL_Kontaktadresse[] kontaktadresse{ get;} + @TestVisible public PDL_KontaktinformasjonForDoedsbo[] kontaktinformasjonForDoedsbo{ get;} + @TestVisible public PDL_Navn[] navn{ get;} + @TestVisible public PDL_Opphold[] opphold{ get;} + @TestVisible public PDL_Oppholdsadresse[] oppholdsadresse{ get;} + @TestVisible public PDL_Sikkerhetstiltak[] sikkerhetstiltak{ get;} + @TestVisible public PDL_Sivilstand[] sivilstand{ get;} + @TestVisible public PDL_Statsborgerskap[] statsborgerskap{ get;} + @TestVisible public PDL_Telefonnummer[] telefonnummer{ get;} + @TestVisible public PDL_TilrettelagtKommunikasjon[] tilrettelagtKommunikasjon{ get;} + @TestVisible public PDL_UtenlandskIdentifikasjonsnummer[] utenlandskIdentifikasjonsnummer{ get;} + @TestVisible public PDL_InnflyttingTilNorge[] innflyttingTilNorge{ get;} + @TestVisible public PDL_UtflyttingFraNorge[] utflyttingFraNorge{ get;} + @TestVisible public PDL_VergemaalEllerFremtidsfullmakt[] vergemaalEllerFremtidsfullmakt{ get;} public PDL_HentPerson() { diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 9566f12e..8cc59004 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -25,31 +25,33 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { private static KafkaPerson3 createBaseKafkaPerson(String actorId) { KafkaPerson3 kp = new KafkaPerson3(); - //kp.hentIdenter.identer = new List(); - //kp.hentPerson.folkeregisteridentifikator = new List(); - //kp.hentPerson.foedselsdato = new List(); - //kp.hentPerson.folkeregisterpersonstatus = new List(); - //kp.hentPerson.navn = new List(); - //kp.hentPerson.bostedsadresse = new KafkaPerson3.Adresser(); - //kp.hentPerson.bostedsadresse.vegadresse = new List(); + kp.hentIdenter = new KafkaPerson3.HentIdenter(); + kp.hentIdenter.identer = new List(); + kp.hentPerson = new PDL_HentPerson(); + kp.hentPerson.adressebeskyttelse = new List(); + kp.hentPerson.bostedsadresse = new List(); //kp.hentPerson.bostedsadresse.matrikkeladresse = new List(); - //kp.hentPerson.bostedsadresse.utenlandskAdresse = new List(); //kp.hentPerson.bostedsadresse.ukjentBosted = new List(); - //kp.hentPerson.oppholdsadresse = new KafkaPerson3.Adresser(); - //kp.hentPerson.oppholdsadresse.vegadresse = new List(); + //kp.hentPerson.bostedsadresse.utenlandskAdresse = new List(); + //kp.hentPerson.bostedsadresse.vegadresse = new List(); + //kp.hentPerson.bydelsnummerFraGt = ''; + kp.hentPerson.doedsfall = new List(); + kp.hentPerson.foedsel = new List(); + kp.hentPerson.folkeregisteridentifikator = new List(); + kp.hentPerson.folkeregisterpersonstatus = new List(); + kp.hentPerson.innflyttingTilNorge = new List(); + kp.hentPerson.kjoenn = new List(); + //kp.hentPerson.kommunenummerFraGt = ''; + kp.hentPerson.navn = new List(); + kp.hentPerson.oppholdsadresse = new List(); //kp.hentPerson.oppholdsadresse.matrikkeladresse = new List(); - //kp.hentPerson.oppholdsadresse.utenlandskAdresse = new List(); //kp.hentPerson.oppholdsadresse.ukjentBosted = new List(); - //kp.hentPerson.innflyttingTilNorge = new List(); - //kp.hentPerson.utflyttingFraNorge = new List(); - //kp.hentPerson.adressebeskyttelse = new List(); - //kp.hentPerson.kommunenummerFraGt = ''; - //kp.hentPerson.bydelsnummerFraGt = ''; - //kp.hentPerson.sivilstand = new List(); - //kp.hentPerson.statsborgerskap = new List(); - //kp.hentPerson.kjoenn = new List(); - //kp.hentPerson.doedsfall = new List(); - //kp.hentPerson.telefonnummer = new List(); + //kp.hentPerson.oppholdsadresse.utenlandskAdresse = new List(); + //kp.hentPerson.oppholdsadresse.vegadresse = new List(); + kp.hentPerson.sivilstand = new List(); + kp.hentPerson.statsborgerskap = new List(); + kp.hentPerson.telefonnummer = new List(); + kp.hentPerson.utflyttingFraNorge = new List(); //Default values //Ident kp.hentIdenter.identer.add(new PDL_IdentInformasjon()); @@ -57,15 +59,14 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { kp.hentIdenter.identer[0].historisk = false; kp.hentIdenter.identer[0].ident = actorId; //Person status - PDL_Folkeregisterpersonstatus status; - status.status = 'bosatt'; - kp.hentPerson.folkeregisterpersonstatus.add(status); + // isn't there a better way than initializing all of these manually? + kp.hentPerson.folkeregisterpersonstatus.add(new PDL_Folkeregisterpersonstatus()); + kp.hentPerson.folkeregisterpersonstatus[0].status = 'bosatt'; //Navn kp.hentPerson.navn.add(new PDL_Navn()); kp.hentPerson.navn[0].etternavn = 'TRESTRESEN'; - PDL_Adressebeskyttelse beskyttelse = new PDL_Adressebeskyttelse(); - beskyttelse.gradering = PDL_AdressebeskyttelseGradering.UGRADERT; - kp.hentPerson.adressebeskyttelse.add(beskyttelse); + kp.hentPerson.adressebeskyttelse.add(new PDL_Adressebeskyttelse()); + kp.hentPerson.adressebeskyttelse[0].gradering = PDL_AdressebeskyttelseGradering.UGRADERT; return kp; } @@ -722,21 +723,25 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { static void setNameException() { KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); - kPerson.hentIdenter.identer[0].ident = '12345678901'; - kPerson.hentIdenter.identer[0].historisk = true; - kPerson.hentIdenter.identer[0].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + Integer i = kPerson.hentIdenter.identer.size() - 1; + kPerson.hentIdenter.identer[i].ident = '12345678901'; + kPerson.hentIdenter.identer[i].historisk = true; + kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); - kPerson.hentIdenter.identer[1].ident = '12345678911'; - kPerson.hentIdenter.identer[1].historisk = true; - kPerson.hentIdenter.identer[1].gruppe = PDL_IdentGruppe.NPID; + i = kPerson.hentIdenter.identer.size() - 1; + kPerson.hentIdenter.identer[i].ident = '12345678911'; + kPerson.hentIdenter.identer[i].historisk = true; + kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.NPID; kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); - kPerson.hentIdenter.identer[2].ident = '5234567890169'; - kPerson.hentIdenter.identer[2].historisk = false; - kPerson.hentIdenter.identer[2].gruppe = PDL_IdentGruppe.AKTORID; + i = kPerson.hentIdenter.identer.size() - 1; + kPerson.hentIdenter.identer[i].ident = '5234567890169'; + kPerson.hentIdenter.identer[i].historisk = false; + kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.AKTORID; kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); - kPerson.hentIdenter.identer[3].ident = '12345678902'; - kPerson.hentIdenter.identer[3].historisk = true; - kPerson.hentIdenter.identer[3].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + i = kPerson.hentIdenter.identer.size() - 1; + kPerson.hentIdenter.identer[i].ident = '12345678902'; + kPerson.hentIdenter.identer[i].historisk = true; + kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; Person__c person = new Person__c(); Test.startTest(); try { diff --git a/force-app/pdl-handler/classes/KafkaPerson3.cls b/force-app/pdl-handler/classes/KafkaPerson3.cls index a2c7af97..c16c4ce4 100644 --- a/force-app/pdl-handler/classes/KafkaPerson3.cls +++ b/force-app/pdl-handler/classes/KafkaPerson3.cls @@ -2,10 +2,13 @@ * Basically a deserializable PDL_Data */ public with sharing class KafkaPerson3 { + @TestVisible public PDL_HentPerson hentPerson{get;} + @TestVisible public HentIdenter hentIdenter{get;} public class HentIdenter { + @TestVisible public PDL_IdentInformasjon[] identer{get;} } From 1e413fa7248777beecf11cdf627b96fd722805ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 29 Jan 2024 15:23:48 +0100 Subject: [PATCH 022/159] add and pass setNameTest --- .../classes/KafkaPdlPersondokumentHandler.cls | 22 ++--- .../KafkaPdlPersondokumentHandlerTest.cls | 95 +++++++++++++++++++ 2 files changed, 105 insertions(+), 12 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index eb4bc858..5a4b753b 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -282,7 +282,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess private Person__c mapFieldValues(Person__c person, KafkaPerson3 kafkaPerson) { KafkaPerson3.HentIdenter hentIdenter = kafkaPerson.hentIdenter; PDL_HentPerson hentPerson = kafkaPerson.hentPerson; - setIdents(person, hentIdenter, hentPerson); + setIdents(person, kafkaPerson); setName(person, hentIdenter); setDateOfBirth(person, hentPerson); @@ -673,17 +673,15 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess /** * Sets ident based on HentIdenter, throws error if none is found. */ - private static void setIdents( - Person__c person, - KafkaPerson3.HentIdenter hentIdenter, - PDL_HentPerson hentPerson - ) { - if (hentIdenter.identer != null && hentIdenter.identer.isEmpty() == false && - hentPerson.folkeregisteridentifikator != null && - hentPerson.folkeregisteridentifikator.isEmpty() == false) { - person.INT_NPID__c = Pdl_IdentUtility.getIdentsFromList(hentIdenter.identer).npid; - person.INT_fnr__c = Pdl_IdentUtility.getIdentsFromList(hentIdenter.identer).fnr; - setFolkeregisterIdents(person, hentPerson.folkeregisteridentifikator); + private static void setIdents(Person__c person, KafkaPerson3 kp) { + PDL_IdentInformasjon[] identer = kp.hentIdenter.identer; + PDL_Folkeregisteridentifikator[] fregIdenter = kp.hentPerson.folkeregisteridentifikator; + if (identer != null && identer.isEmpty() == false && + fregIdenter != null && + fregIdenter.isEmpty() == false) { + person.INT_NPID__c = Pdl_IdentUtility.getIdentsFromList(identer).npid; + person.INT_fnr__c = Pdl_IdentUtility.getIdentsFromList(identer).fnr; + setFolkeregisterIdents(person, fregIdenter); } else { throw new PdlIdentException('Not able to set person idents from Kafka'); } diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 8cc59004..8a54ed53 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -719,7 +719,56 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual(null, p.INT_LastName__c, 'Lastname'); } + /******************************************* + * TESTS FOR idents * + *******************************************/ + + @isTest + /** + * Tests that person's Name is set to FOLKEREGISTERIDENT when both + * FOLKEREGISTERIDENT and NPID exist and are not historic. + * Also tests that Name is set to NPID when the FOLKEREGISTERIDENT exists + * but is historic. + */ + static void setNameTest() { + KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); + kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); + Integer i = kPerson.hentIdenter.identer.size() - 1; + kPerson.hentIdenter.identer[i].ident = '12345678901'; + kPerson.hentIdenter.identer[i].historisk = false; + kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + Integer fregIndex = i; + kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); + i = kPerson.hentIdenter.identer.size() - 1; + kPerson.hentIdenter.identer[i].ident = '12345678911'; + kPerson.hentIdenter.identer[i].historisk = false; + kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.NPID; + kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); + i = kPerson.hentIdenter.identer.size() - 1; + kPerson.hentIdenter.identer[i].ident = '5234567890169'; + kPerson.hentIdenter.identer[i].historisk = false; + kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.AKTORID; + kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); + i = kPerson.hentIdenter.identer.size() - 1; + kPerson.hentIdenter.identer[i].ident = '12345678902'; + kPerson.hentIdenter.identer[i].historisk = true; + kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + Person__c person = new Person__c(); + Test.startTest(); + KafkaPdlPersondokumentHandler.setName(person, kPerson.hentIdenter); + System.assertEquals('12345678901', person.Name, 'Expected non historisk FOLKEREGISTERIDENT'); + person = new Person__c(); + kPerson.hentIdenter.identer[fregIndex].historisk = true; + KafkaPdlPersondokumentHandler.setName(person, kPerson.hentIdenter); + System.assertEquals('12345678911', person.Name, 'Expected non historisk NPID'); + Test.stopTest(); + } + @IsTest + /** + * Tests that person's Name is not set and instead an exception is thrown + * when FOLKEREGISTERIDENT and NPID exist but are historic. + */ static void setNameException() { KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); @@ -755,4 +804,50 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Test.stopTest(); } + @IsTest + /** + * Create a person with an (active) FNR and an (inactive) DNR, ensure both + * are set. + */ + static void setIdentsTest() { + KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); + PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); + identInfo.ident = '12345678901'; + identInfo.historisk = false; + identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + kPerson.hentIdenter.identer.add(identInfo); + identInfo = new PDL_IdentInformasjon(); + identInfo.ident = '12345678911'; + identInfo.historisk = false; + identInfo.gruppe = PDL_IdentGruppe.NPID; + kPerson.hentIdenter.identer.add(identInfo); + identInfo = new PDL_IdentInformasjon(); + identInfo.ident = '52345678901'; + identInfo.historisk = true; + identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + kPerson.hentIdenter.identer.add(identInfo); + PDL_FolkeregisterIdentifikator fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent.identifikasjonsnummer = '12345678901'; + fregIdent.status = PDL_IdentStatus.I_BRUK; + fregIdent.type = PDL_IdentType.FNR; + fregIdent.metadata = new PDL_Metadata(); + fregIdent.metadata.historisk = false; + kPerson.hentPerson.folkeregisteridentifikator.add(fregIdent); + fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent.identifikasjonsnummer = '52345678901'; + fregIdent.status = PDL_IdentStatus.OPPHOERT; + fregIdent.type = PDL_IdentType.DNR; + fregIdent.metadata = new PDL_Metadata(); + fregIdent.metadata.historisk = true; + kPerson.hentPerson.folkeregisteridentifikator.add(fregIdent); + Person__c person = new Person__c(); + Test.startTest(); + KafkaPdlPersondokumentHandler.setIdents(person, kPerson); + Test.stopTest(); + System.assertEquals(null, person.INT_ACTORID__c, 'Expected AKTORID to be null'); + System.assertEquals('12345678901', person.INT_FNR__c, 'Expected FNR to be set'); + System.assertEquals('12345678911', person.INT_NPID__c, 'Expect NPID to be set'); + System.assertEquals('52345678901', person.INT_DNR__c, 'Expect DNR to be set'); + } + } From 24e4b03f375f59f980de1aa449d25558d8c7ea5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 29 Jan 2024 17:24:37 +0100 Subject: [PATCH 023/159] fix logic, pass test --- .../classes/KafkaPdlPersondokumentHandler.cls | 11 +- .../KafkaPdlPersondokumentHandlerTest.cls | 262 +++++++++--------- 2 files changed, 139 insertions(+), 134 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 5a4b753b..58d46cdd 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -671,7 +671,12 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess @TestVisible /** - * Sets ident based on HentIdenter, throws error if none is found. + * Sets ident based on both HentIdenter and HentPerson: + * - NPID from HentIdenter + * - _not_ FNR from HentIdenter, for whatever reason + * - FNR from HentPerson, overrides the above + * - DNR from HentPerson + * Throws error unless both HentIdenter and HentPerson exist. */ private static void setIdents(Person__c person, KafkaPerson3 kp) { PDL_IdentInformasjon[] identer = kp.hentIdenter.identer; @@ -680,7 +685,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess fregIdenter != null && fregIdenter.isEmpty() == false) { person.INT_NPID__c = Pdl_IdentUtility.getIdentsFromList(identer).npid; - person.INT_fnr__c = Pdl_IdentUtility.getIdentsFromList(identer).fnr; + //person.INT_fnr__c = Pdl_IdentUtility.getIdentsFromList(identer).fnr; setFolkeregisterIdents(person, fregIdenter); } else { throw new PdlIdentException('Not able to set person idents from Kafka'); @@ -694,7 +699,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } private static void assignDnrIfAppropriate(Person__c p, PDL_FolkeregisterIdentifikator id) { - if (id.type == PDL_IdentType.DNR && String.isBlank(p.INT_dnr__c) || !id.metadata.historisk) { + if (id.type == PDL_IdentType.DNR && (String.isBlank(p.INT_dnr__c) || !id.metadata.historisk)) { p.INT_dnr__c = id.identifikasjonsnummer; } } diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 8a54ed53..7407c6f9 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -425,6 +425,137 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Test.stopTest(); } + /******************************************* + * TESTS FOR idents * + *******************************************/ + + @isTest + /** + * Tests that person's Name is set to FOLKEREGISTERIDENT when both + * FOLKEREGISTERIDENT and NPID exist and are not historic. + * Also tests that Name is set to NPID when the FOLKEREGISTERIDENT exists + * but is historic. + */ + static void setNameTest() { + KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); + kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); + Integer i = kPerson.hentIdenter.identer.size() - 1; + kPerson.hentIdenter.identer[i].ident = '12345678901'; + kPerson.hentIdenter.identer[i].historisk = false; + kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + Integer fregIndex = i; + kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); + i = kPerson.hentIdenter.identer.size() - 1; + kPerson.hentIdenter.identer[i].ident = '12345678911'; + kPerson.hentIdenter.identer[i].historisk = false; + kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.NPID; + kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); + i = kPerson.hentIdenter.identer.size() - 1; + kPerson.hentIdenter.identer[i].ident = '5234567890169'; + kPerson.hentIdenter.identer[i].historisk = false; + kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.AKTORID; + kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); + i = kPerson.hentIdenter.identer.size() - 1; + kPerson.hentIdenter.identer[i].ident = '12345678902'; + kPerson.hentIdenter.identer[i].historisk = true; + kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + Person__c person = new Person__c(); + Test.startTest(); + KafkaPdlPersondokumentHandler.setName(person, kPerson.hentIdenter); + Assert.areEqual('12345678901', person.Name, 'Expected non historisk FOLKEREGISTERIDENT'); + person = new Person__c(); + kPerson.hentIdenter.identer[fregIndex].historisk = true; + KafkaPdlPersondokumentHandler.setName(person, kPerson.hentIdenter); + Assert.areEqual('12345678911', person.Name, 'Expected non historisk NPID'); + Test.stopTest(); + } + + @IsTest + /** + * Tests that person's Name is not set and instead an exception is thrown + * when FOLKEREGISTERIDENT and NPID exist but are historic. + */ + static void setNameException() { + KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); + kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); + Integer i = kPerson.hentIdenter.identer.size() - 1; + kPerson.hentIdenter.identer[i].ident = '12345678901'; + kPerson.hentIdenter.identer[i].historisk = true; + kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); + i = kPerson.hentIdenter.identer.size() - 1; + kPerson.hentIdenter.identer[i].ident = '12345678911'; + kPerson.hentIdenter.identer[i].historisk = true; + kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.NPID; + kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); + i = kPerson.hentIdenter.identer.size() - 1; + kPerson.hentIdenter.identer[i].ident = '5234567890169'; + kPerson.hentIdenter.identer[i].historisk = false; + kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.AKTORID; + kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); + i = kPerson.hentIdenter.identer.size() - 1; + kPerson.hentIdenter.identer[i].ident = '12345678902'; + kPerson.hentIdenter.identer[i].historisk = true; + kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + Person__c person = new Person__c(); + Test.startTest(); + try { + KafkaPdlPersondokumentHandler.setName(person, kPerson.hentIdenter); + Assert.fail('No exception thrown'); + } catch (KafkaPdlPersondokumentHandler.PdlIdentException ex) { + System.assert(true); // ಠ_ಠ + } catch (Exception e) { + Assert.fail('Did not catch the correct exception'); + } + Test.stopTest(); + } + + @IsTest + /** + * Create a person with an (active) FNR and an (inactive) DNR, ensure both + * are set. + */ + static void setIdentsTest() { + KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); + PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); + identInfo.ident = '12345678901'; + identInfo.historisk = false; + identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + kPerson.hentIdenter.identer.add(identInfo); + identInfo = new PDL_IdentInformasjon(); + identInfo.ident = '12345678911'; + identInfo.historisk = false; + identInfo.gruppe = PDL_IdentGruppe.NPID; + kPerson.hentIdenter.identer.add(identInfo); + identInfo = new PDL_IdentInformasjon(); + identInfo.ident = '52345678901'; + identInfo.historisk = true; + identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + kPerson.hentIdenter.identer.add(identInfo); + PDL_FolkeregisterIdentifikator fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent.identifikasjonsnummer = '12345678901'; + fregIdent.status = PDL_IdentStatus.I_BRUK; + fregIdent.type = PDL_IdentType.FNR; + fregIdent.metadata = new PDL_Metadata(); + fregIdent.metadata.historisk = false; + kPerson.hentPerson.folkeregisteridentifikator.add(fregIdent); + fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent.identifikasjonsnummer = '52345678901'; + fregIdent.status = PDL_IdentStatus.OPPHOERT; + fregIdent.type = PDL_IdentType.DNR; + fregIdent.metadata = new PDL_Metadata(); + fregIdent.metadata.historisk = true; + kPerson.hentPerson.folkeregisteridentifikator.add(fregIdent); + Person__c person = new Person__c(); + Test.startTest(); + KafkaPdlPersondokumentHandler.setIdents(person, kPerson); + Test.stopTest(); + Assert.areEqual(null, person.INT_ACTORID__c, 'Expected AKTORID to be null'); + Assert.areEqual('12345678901', person.INT_FNR__c, 'Expected FNR to be set'); + Assert.areEqual('12345678911', person.INT_NPID__c, 'Expect NPID to be set'); + Assert.areEqual('52345678901', person.INT_DNR__c, 'Expect DNR to be set'); + } + /******************************************* * TESTS FOR checkLastUpdatedAndTombStones * *******************************************/ @@ -719,135 +850,4 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual(null, p.INT_LastName__c, 'Lastname'); } - /******************************************* - * TESTS FOR idents * - *******************************************/ - - @isTest - /** - * Tests that person's Name is set to FOLKEREGISTERIDENT when both - * FOLKEREGISTERIDENT and NPID exist and are not historic. - * Also tests that Name is set to NPID when the FOLKEREGISTERIDENT exists - * but is historic. - */ - static void setNameTest() { - KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); - kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); - Integer i = kPerson.hentIdenter.identer.size() - 1; - kPerson.hentIdenter.identer[i].ident = '12345678901'; - kPerson.hentIdenter.identer[i].historisk = false; - kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - Integer fregIndex = i; - kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); - i = kPerson.hentIdenter.identer.size() - 1; - kPerson.hentIdenter.identer[i].ident = '12345678911'; - kPerson.hentIdenter.identer[i].historisk = false; - kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.NPID; - kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); - i = kPerson.hentIdenter.identer.size() - 1; - kPerson.hentIdenter.identer[i].ident = '5234567890169'; - kPerson.hentIdenter.identer[i].historisk = false; - kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.AKTORID; - kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); - i = kPerson.hentIdenter.identer.size() - 1; - kPerson.hentIdenter.identer[i].ident = '12345678902'; - kPerson.hentIdenter.identer[i].historisk = true; - kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - Person__c person = new Person__c(); - Test.startTest(); - KafkaPdlPersondokumentHandler.setName(person, kPerson.hentIdenter); - System.assertEquals('12345678901', person.Name, 'Expected non historisk FOLKEREGISTERIDENT'); - person = new Person__c(); - kPerson.hentIdenter.identer[fregIndex].historisk = true; - KafkaPdlPersondokumentHandler.setName(person, kPerson.hentIdenter); - System.assertEquals('12345678911', person.Name, 'Expected non historisk NPID'); - Test.stopTest(); - } - - @IsTest - /** - * Tests that person's Name is not set and instead an exception is thrown - * when FOLKEREGISTERIDENT and NPID exist but are historic. - */ - static void setNameException() { - KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); - kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); - Integer i = kPerson.hentIdenter.identer.size() - 1; - kPerson.hentIdenter.identer[i].ident = '12345678901'; - kPerson.hentIdenter.identer[i].historisk = true; - kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); - i = kPerson.hentIdenter.identer.size() - 1; - kPerson.hentIdenter.identer[i].ident = '12345678911'; - kPerson.hentIdenter.identer[i].historisk = true; - kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.NPID; - kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); - i = kPerson.hentIdenter.identer.size() - 1; - kPerson.hentIdenter.identer[i].ident = '5234567890169'; - kPerson.hentIdenter.identer[i].historisk = false; - kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.AKTORID; - kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); - i = kPerson.hentIdenter.identer.size() - 1; - kPerson.hentIdenter.identer[i].ident = '12345678902'; - kPerson.hentIdenter.identer[i].historisk = true; - kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - Person__c person = new Person__c(); - Test.startTest(); - try { - KafkaPdlPersondokumentHandler.setName(person, kPerson.hentIdenter); - System.assert(false, 'No exception thrown'); - } catch (KafkaPdlPersondokumentHandler.PdlIdentException ex) { - System.assert(true); - } catch (Exception e) { - System.assert(false, 'Did not catch the correct exception'); - } - Test.stopTest(); - } - - @IsTest - /** - * Create a person with an (active) FNR and an (inactive) DNR, ensure both - * are set. - */ - static void setIdentsTest() { - KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); - PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); - identInfo.ident = '12345678901'; - identInfo.historisk = false; - identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - kPerson.hentIdenter.identer.add(identInfo); - identInfo = new PDL_IdentInformasjon(); - identInfo.ident = '12345678911'; - identInfo.historisk = false; - identInfo.gruppe = PDL_IdentGruppe.NPID; - kPerson.hentIdenter.identer.add(identInfo); - identInfo = new PDL_IdentInformasjon(); - identInfo.ident = '52345678901'; - identInfo.historisk = true; - identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - kPerson.hentIdenter.identer.add(identInfo); - PDL_FolkeregisterIdentifikator fregIdent = new PDL_FolkeregisterIdentifikator(); - fregIdent.identifikasjonsnummer = '12345678901'; - fregIdent.status = PDL_IdentStatus.I_BRUK; - fregIdent.type = PDL_IdentType.FNR; - fregIdent.metadata = new PDL_Metadata(); - fregIdent.metadata.historisk = false; - kPerson.hentPerson.folkeregisteridentifikator.add(fregIdent); - fregIdent = new PDL_FolkeregisterIdentifikator(); - fregIdent.identifikasjonsnummer = '52345678901'; - fregIdent.status = PDL_IdentStatus.OPPHOERT; - fregIdent.type = PDL_IdentType.DNR; - fregIdent.metadata = new PDL_Metadata(); - fregIdent.metadata.historisk = true; - kPerson.hentPerson.folkeregisteridentifikator.add(fregIdent); - Person__c person = new Person__c(); - Test.startTest(); - KafkaPdlPersondokumentHandler.setIdents(person, kPerson); - Test.stopTest(); - System.assertEquals(null, person.INT_ACTORID__c, 'Expected AKTORID to be null'); - System.assertEquals('12345678901', person.INT_FNR__c, 'Expected FNR to be set'); - System.assertEquals('12345678911', person.INT_NPID__c, 'Expect NPID to be set'); - System.assertEquals('52345678901', person.INT_DNR__c, 'Expect DNR to be set'); - } - } From b518d00c0bf3a5ee4d34802a89eeef270401ac01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 29 Jan 2024 18:19:12 +0100 Subject: [PATCH 024/159] add and pass insertKafkaMessageDefault --- .../KafkaPdlPersondokumentHandlerTest.cls | 72 ++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 7407c6f9..552949e7 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -426,7 +426,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { } /******************************************* - * TESTS FOR idents * + * TESTS FOR IDENTS * *******************************************/ @isTest @@ -850,4 +850,74 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual(null, p.INT_LastName__c, 'Lastname'); } + /******************************** + * TESTS FOR MESSAGE PROCESSING * + ********************************/ + + private static KafkaMessage__c createKafkaMessage( + String aktorId, + KafkaPerson3 kafkaPerson + ) { + KafkaMessage__c kafkaMessage = new KafkaMessage__c( + CRM_Key__c = aktorId, + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf(JSON.serialize(kafkaPerson))), + CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1' + ); + + return kafkaMessage; + } + + private static void assertProcessed(KafkaMessage__c message) { + Assert.areEqual( + KafkaMessageService.STATUS_PROCESSED, + message.CRM_Status__c, + 'Expected message to be processed but it is ' + + message.CRM_Status__c + + '. CRM_ErrorMessage__c: ' + + message.CRM_ErrorMessage__c + ); + } + + @isTest + /** + * Create, insert, and process a message. + */ + static void insertKafkaMessageDefault() { + KafkaPerson3 kafkaPerson = createBaseKafkaPerson('11223344556'); + PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); + identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + identInfo.historisk = false; + identInfo.ident = '12345678901'; + kafkaPerson.hentIdenter.identer.add(identInfo); + PDL_FolkeregisterIdentifikator fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent.identifikasjonsnummer = '12345678901'; + fregIdent.type = PDL_IdentType.FNR; + fregIdent.status = PDL_IdentStatus.I_BRUK; + fregIdent.metadata = new PDL_Metadata(); + fregIdent.metadata.historisk = false; + kafkaPerson.hentPerson.folkeregisteridentifikator.add(fregIdent); + KafkaMessage__c message = createKafkaMessage('11223344556', kafkaPerson); + // Verify that we don't have any Person__c records + Assert.areEqual(0, [SELECT COUNT() FROM Person__c]); + // Act + Test.startTest(); + insert message; + AsyncRequestSchedulable.enqueueAsyncJobs(); + Test.stopTest(); + assertProcessed( + [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message.Id LIMIT 1] + ); + Assert.areEqual(1, [SELECT COUNT() FROM Person__c]); + Person__c person = [ + SELECT FIELDS(STANDARD), INT_ActorId__c, INT_fnr__c, INT_dnr__c, INT_npid__c + FROM Person__c + WHERE INT_actorId__c = '11223344556' + ]; + Assert.areEqual('12345678901', person.INT_fnr__c, 'Expect FNR to be set'); + Assert.areEqual(null, person.INT_npid__c, 'Did not expect NPID to be set'); + Assert.areEqual(null, person.INT_dnr__c, 'Did not expect DNR to be set'); + Assert.areEqual('12345678901', person.Name, 'Expected NAME to be set'); + Assert.areEqual('11223344556', person.INT_actorId__c, 'Expected AKTØRID to be set'); + } + } From 9e0ad9b21f4e9dd9ad20d67f82aa123969bc9099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 30 Jan 2024 14:20:30 +0100 Subject: [PATCH 025/159] add insertKafkaMessageProcessed test which fails --- .../KafkaPdlPersondokumentHandlerTest.cls | 97 ++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 552949e7..22de6508 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -854,13 +854,21 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { * TESTS FOR MESSAGE PROCESSING * ********************************/ + /** + * Create a message similar to one we would receive via Kafka. Note that + * JSON.serialize(null) correctly becomes the string "null", however, the + * value denoting a tombstone is not the base64 encoding of this string, but + * simply null. Take this into account. + */ private static KafkaMessage__c createKafkaMessage( String aktorId, KafkaPerson3 kafkaPerson ) { KafkaMessage__c kafkaMessage = new KafkaMessage__c( CRM_Key__c = aktorId, - CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf(JSON.serialize(kafkaPerson))), + CRM_Value__c = (kafkaPerson == null ? + null : + EncodingUtil.base64Encode(Blob.valueOf(JSON.serialize(kafkaPerson)))), CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1' ); @@ -920,4 +928,91 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('11223344556', person.INT_actorId__c, 'Expected AKTØRID to be set'); } + @isTest + /** + * don't know what this one tests, so keep it + */ + static void insertKafkaMessageProcessed() { + KafkaPerson3 athos = createBaseKafkaPerson('11223344556'); + PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); + identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + identInfo.historisk = false; + identInfo.ident = '12345678901'; + athos.hentIdenter.identer.add(identInfo); + PDL_FolkeregisterIdentifikator fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent.status = PDL_IdentStatus.I_BRUK; + fregIdent.type = PDL_IdentType.FNR; + fregIdent.identifikasjonsnummer = '12345678901'; + fregIdent.metadata = new PDL_Metadata(); + fregIdent.metadata.historisk = false; + athos.hentPerson.folkeregisteridentifikator.add(fregIdent); + KafkaPerson3 porthos = createBaseKafkaPerson('11223344556'); + identInfo = new PDL_IdentInformasjon(); + identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + identInfo.historisk = false; + identInfo.ident = '12345678901'; + porthos.hentIdenter.identer.add(identInfo); + fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent.status = PDL_IdentStatus.I_BRUK; + fregIdent.type = PDL_IdentType.FNR; + fregIdent.identifikasjonsnummer = '12345678901'; + fregIdent.metadata = new PDL_Metadata(); + fregIdent.metadata.historisk = false; + porthos.hentPerson.folkeregisteridentifikator.add(fregIdent); + // porthos.sikkerhetstiltak = new List(); // looks like this is well deprecated + porthos.hentPerson.sikkerhetstiltak = new List(); + porthos.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); + porthos.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); + porthos.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); // wtf? + KafkaPerson3 aramis = createBaseKafkaPerson('11223344556'); + identInfo = new PDL_IdentInformasjon(); + identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + identInfo.historisk = false; + identInfo.ident = '12345678901'; + aramis.hentIdenter.identer.add(identInfo); + fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent.status = PDL_IdentStatus.I_BRUK; + fregIdent.type = PDL_IdentType.FNR; + fregIdent.identifikasjonsnummer = '12345678901'; + fregIdent.metadata = new PDL_Metadata(); + fregIdent.metadata.historisk = false; + porthos.hentPerson.folkeregisteridentifikator.add(fregIdent); + //KafkaMessage__c message1 = createKafkaMessageHelper(createBaseKafkaPerson('11223344557'), '11223344557', true); + KafkaMessage__c message1 = createKafkaMessage('11223344557', null); + KafkaMessage__c message2 = createKafkaMessage('11223344556', athos); + KafkaMessage__c message3 = createKafkaMessage('11223344556', porthos); + //KafkaMessage__c message4 = createKafkaMessageHelper(aramis, '11223344556', true); + KafkaMessage__c message4 = createKafkaMessage('11223344556', null); + // Act + Test.startTest(); + insert new List{ message1, message2, message3, message4 }; + AsyncRequestSchedulable.enqueueAsyncJobs(); + Test.stopTest(); + message1 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message1.Id]; + message2 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message2.Id]; + message3 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message3.Id]; + message4 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message4.Id]; + Assert.areEqual( + KafkaMessageService.STATUS_PROCESSED, + message1.CRM_Status__c, + '' + message1.CRM_ErrorMessage__c + ); + Assert.areEqual( + KafkaMessageService.STATUS_WARNING, + message2.CRM_Status__c, + '' + message2.CRM_ErrorMessage__c + ); + Assert.areEqual( + KafkaMessageService.STATUS_WARNING, + message3.CRM_Status__c, + '' + message3.CRM_ErrorMessage__c + ); + Assert.areEqual( + KafkaMessageService.STATUS_PROCESSED, + message4.CRM_Status__c, + '' + message4.CRM_ErrorMessage__c + ); + Assert.areEqual(0, [SELECT COUNT() FROM Person__c WHERE Name = '12345678901']); + } + } From 6e7686287f5b6f29a938d57dcb769e1d09adeb20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 30 Jan 2024 16:51:24 +0100 Subject: [PATCH 026/159] ditch the non-actorid-looking actorids --- .../KafkaPdlPersondokumentHandlerTest.cls | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 22de6508..814474c9 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -891,7 +891,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { * Create, insert, and process a message. */ static void insertKafkaMessageDefault() { - KafkaPerson3 kafkaPerson = createBaseKafkaPerson('11223344556'); + KafkaPerson3 kafkaPerson = createBaseKafkaPerson('1122334455666'); PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; identInfo.historisk = false; @@ -904,7 +904,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { fregIdent.metadata = new PDL_Metadata(); fregIdent.metadata.historisk = false; kafkaPerson.hentPerson.folkeregisteridentifikator.add(fregIdent); - KafkaMessage__c message = createKafkaMessage('11223344556', kafkaPerson); + KafkaMessage__c message = createKafkaMessage('1122334455666', kafkaPerson); // Verify that we don't have any Person__c records Assert.areEqual(0, [SELECT COUNT() FROM Person__c]); // Act @@ -919,13 +919,13 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Person__c person = [ SELECT FIELDS(STANDARD), INT_ActorId__c, INT_fnr__c, INT_dnr__c, INT_npid__c FROM Person__c - WHERE INT_actorId__c = '11223344556' + WHERE INT_actorId__c = '1122334455666' ]; Assert.areEqual('12345678901', person.INT_fnr__c, 'Expect FNR to be set'); Assert.areEqual(null, person.INT_npid__c, 'Did not expect NPID to be set'); Assert.areEqual(null, person.INT_dnr__c, 'Did not expect DNR to be set'); Assert.areEqual('12345678901', person.Name, 'Expected NAME to be set'); - Assert.areEqual('11223344556', person.INT_actorId__c, 'Expected AKTØRID to be set'); + Assert.areEqual('1122334455666', person.INT_actorId__c, 'Expected AKTØRID to be set'); } @isTest @@ -933,7 +933,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { * don't know what this one tests, so keep it */ static void insertKafkaMessageProcessed() { - KafkaPerson3 athos = createBaseKafkaPerson('11223344556'); + KafkaPerson3 athos = createBaseKafkaPerson('1122334455666'); PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; identInfo.historisk = false; @@ -946,7 +946,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { fregIdent.metadata = new PDL_Metadata(); fregIdent.metadata.historisk = false; athos.hentPerson.folkeregisteridentifikator.add(fregIdent); - KafkaPerson3 porthos = createBaseKafkaPerson('11223344556'); + KafkaPerson3 porthos = createBaseKafkaPerson('1122334455666'); identInfo = new PDL_IdentInformasjon(); identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; identInfo.historisk = false; @@ -964,7 +964,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { porthos.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); porthos.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); porthos.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); // wtf? - KafkaPerson3 aramis = createBaseKafkaPerson('11223344556'); + KafkaPerson3 aramis = createBaseKafkaPerson('1122334455666'); identInfo = new PDL_IdentInformasjon(); identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; identInfo.historisk = false; @@ -977,12 +977,12 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { fregIdent.metadata = new PDL_Metadata(); fregIdent.metadata.historisk = false; porthos.hentPerson.folkeregisteridentifikator.add(fregIdent); - //KafkaMessage__c message1 = createKafkaMessageHelper(createBaseKafkaPerson('11223344557'), '11223344557', true); - KafkaMessage__c message1 = createKafkaMessage('11223344557', null); - KafkaMessage__c message2 = createKafkaMessage('11223344556', athos); - KafkaMessage__c message3 = createKafkaMessage('11223344556', porthos); - //KafkaMessage__c message4 = createKafkaMessageHelper(aramis, '11223344556', true); - KafkaMessage__c message4 = createKafkaMessage('11223344556', null); + //KafkaMessage__c message1 = createKafkaMessageHelper(createBaseKafkaPerson('1122334455777'), '1122334455777', true); + KafkaMessage__c message1 = createKafkaMessage('1122334455777', null); + KafkaMessage__c message2 = createKafkaMessage('1122334455666', athos); + KafkaMessage__c message3 = createKafkaMessage('1122334455666', porthos); + //KafkaMessage__c message4 = createKafkaMessageHelper(aramis, '1122334455666', true); + KafkaMessage__c message4 = createKafkaMessage('1122334455666', null); // Act Test.startTest(); insert new List{ message1, message2, message3, message4 }; From 7476bafd77d1dd6a2e8d2e292e2c9343716c2cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 30 Jan 2024 18:49:26 +0100 Subject: [PATCH 027/159] look at error messages and add a comment --- .../pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 814474c9..187e0c97 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -930,7 +930,8 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { @isTest /** - * don't know what this one tests, so keep it + * All this huge method seems to test is that persons are not updated when + * there exists a tombstone with the same ident. */ static void insertKafkaMessageProcessed() { KafkaPerson3 athos = createBaseKafkaPerson('1122334455666'); From 74704d956d8730c92774c04afb9d5e9d0a0c7eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 31 Jan 2024 14:56:12 +0100 Subject: [PATCH 028/159] add failing test insertKafkaMessageWarning --- .../KafkaPdlPersondokumentHandlerTest.cls | 71 ++++++++++++++++++- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 187e0c97..799bcd6e 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -930,8 +930,8 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { @isTest /** - * All this huge method seems to test is that persons are not updated when - * there exists a tombstone with the same ident. + * All this method seems to test is that persons are not updated when + * there exists a (processed) tombstone with the same ident. */ static void insertKafkaMessageProcessed() { KafkaPerson3 athos = createBaseKafkaPerson('1122334455666'); @@ -1016,4 +1016,71 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual(0, [SELECT COUNT() FROM Person__c WHERE Name = '12345678901']); } + @isTest + /** + * Forces and catches nullpointerexception caused by attempting to create a + * security measure with nonexistent INT_ValidFromDate__c. Catching this + * exception should create the warning from the method name. + */ + static void insertKafkaMessageWarning() { + KafkaPerson3 laurel = createBaseKafkaPerson('1122334455666'); + PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); + identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + identInfo.historisk = false; + identInfo.ident = '12345678901'; + laurel.hentIdenter.identer.add(identInfo); + PDL_FolkeregisterIdentifikator fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent.status = PDL_IdentStatus.I_BRUK; + fregIdent.type = PDL_IdentType.FNR; + fregIdent.identifikasjonsnummer = '12345678901'; + fregIdent.metadata = new PDL_Metadata(); + fregIdent.metadata.historisk = false; + laurel.hentPerson.folkeregisteridentifikator.add(fregIdent); + KafkaPerson3 hardy = createBaseKafkaPerson('1122334455666'); + identInfo = new PDL_IdentInformasjon(); + identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + identInfo.historisk = false; + identInfo.ident = '12345678901'; + hardy.hentIdenter.identer.add(identInfo); + fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent.status = PDL_IdentStatus.I_BRUK; + fregIdent.type = PDL_IdentType.FNR; + fregIdent.identifikasjonsnummer = '12345678901'; + fregIdent.metadata = new PDL_Metadata(); + fregIdent.metadata.historisk = false; + hardy.hentPerson.folkeregisteridentifikator.add(fregIdent); + // hardy.sikkerhetstiltak = new List(); // looks like this is well deprecated + hardy.hentPerson.sikkerhetstiltak = new List(); + hardy.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); + hardy.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); + hardy.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); // wtf? + KafkaMessage__c message1 = createKafkaMessage('11223344557', null); + KafkaMessage__c message2 = createKafkaMessage('11223344556', laurel); + KafkaMessage__c message3 = createKafkaMessage('11223344556', hardy); + // Act + Test.startTest(); + insert new List{ message1, message2, message3 }; + AsyncRequestSchedulable.enqueueAsyncJobs(); + Test.stopTest(); + message1 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message1.Id]; + message2 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message2.Id]; + message3 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message3.Id]; + Assert.areEqual( + KafkaMessageService.STATUS_PROCESSED, + message1.CRM_Status__c, + '' + message1.CRM_ErrorMessage__c + ); + Assert.areEqual( + KafkaMessageService.STATUS_PROCESSED, + message2.CRM_Status__c, + '' + message2.CRM_ErrorMessage__c + ); + Assert.areEqual( + KafkaMessageService.STATUS_WARNING, + message3.CRM_Status__c, + '' + message3.CRM_ErrorMessage__c + ); + Assert.areEqual(0, [SELECT COUNT() FROM Person__c WHERE Name = '12345678901']); + } + } From ea909839e99388c4255f567613849affd647d7f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 31 Jan 2024 15:40:25 +0100 Subject: [PATCH 029/159] readd security measures, pass test --- .../pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 58d46cdd..f4e479d2 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -311,10 +311,12 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess // adressebeskyttelse person.INT_Confidential__c = setClearanceLevel(kafkaPerson.adressebeskyttelse); + */ // sikkerhetstiltak - person.INT_SecurityMeasures__c = JSON.serialize(kafkaPerson.sikkerhetstiltak); + person.INT_SecurityMeasures__c = JSON.serialize(kafkaPerson.hentPerson.sikkerhetstiltak); + /* // adresse setAddress(person, kafkaPerson); From 46aea71064ff7502f0f6f3b4ecf531c0e7775dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 31 Jan 2024 15:50:26 +0100 Subject: [PATCH 030/159] delete no longer used or never used test code --- .../KafkaPdlPersondokumentHandlerTest.cls | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 799bcd6e..9fde3376 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -960,29 +960,10 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { fregIdent.metadata = new PDL_Metadata(); fregIdent.metadata.historisk = false; porthos.hentPerson.folkeregisteridentifikator.add(fregIdent); - // porthos.sikkerhetstiltak = new List(); // looks like this is well deprecated - porthos.hentPerson.sikkerhetstiltak = new List(); - porthos.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); - porthos.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); - porthos.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); // wtf? - KafkaPerson3 aramis = createBaseKafkaPerson('1122334455666'); - identInfo = new PDL_IdentInformasjon(); - identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; - identInfo.historisk = false; - identInfo.ident = '12345678901'; - aramis.hentIdenter.identer.add(identInfo); - fregIdent = new PDL_FolkeregisterIdentifikator(); - fregIdent.status = PDL_IdentStatus.I_BRUK; - fregIdent.type = PDL_IdentType.FNR; - fregIdent.identifikasjonsnummer = '12345678901'; - fregIdent.metadata = new PDL_Metadata(); - fregIdent.metadata.historisk = false; - porthos.hentPerson.folkeregisteridentifikator.add(fregIdent); //KafkaMessage__c message1 = createKafkaMessageHelper(createBaseKafkaPerson('1122334455777'), '1122334455777', true); KafkaMessage__c message1 = createKafkaMessage('1122334455777', null); KafkaMessage__c message2 = createKafkaMessage('1122334455666', athos); KafkaMessage__c message3 = createKafkaMessage('1122334455666', porthos); - //KafkaMessage__c message4 = createKafkaMessageHelper(aramis, '1122334455666', true); KafkaMessage__c message4 = createKafkaMessage('1122334455666', null); // Act Test.startTest(); From 121b5bd650d5f7b17525569e85eaf38ead0ccc3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 31 Jan 2024 17:53:56 +0100 Subject: [PATCH 031/159] realistic actor ids --- .../classes/KafkaPdlPersondokumentHandlerTest.cls | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 9fde3376..03353819 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1035,9 +1035,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { hardy.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); hardy.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); hardy.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); // wtf? - KafkaMessage__c message1 = createKafkaMessage('11223344557', null); - KafkaMessage__c message2 = createKafkaMessage('11223344556', laurel); - KafkaMessage__c message3 = createKafkaMessage('11223344556', hardy); + KafkaMessage__c message1 = createKafkaMessage('1122334455777', null); + KafkaMessage__c message2 = createKafkaMessage('1122334455666', laurel); + KafkaMessage__c message3 = createKafkaMessage('1122334455666', hardy); // Act Test.startTest(); insert new List{ message1, message2, message3 }; From e7cc349b8a2b2fcebc15136caab4d751e7759423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 31 Jan 2024 18:35:55 +0100 Subject: [PATCH 032/159] add and pass insertKafkaMessageUpdateError --- .../KafkaPdlPersondokumentHandlerTest.cls | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 03353819..e4cee1f2 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1064,4 +1064,110 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual(0, [SELECT COUNT() FROM Person__c WHERE Name = '12345678901']); } + @isTest + /** + * TODO check what exactly this tests + */ + static void insertKafkaMessageUpdateError() { + insert new Person__c( + Name = '12345678901', + INT_fnr__c = '12345678901', + INT_ActorId__c = '1122334455666', + INT_FirstName__c = 'FNAME', + INT_LastName__c = 'LNAME' + ); + KafkaPerson3 athos = createBaseKafkaPerson('1122334455666'); + PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); + identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + identInfo.historisk = false; + identInfo.ident = '12345678901'; + athos.hentIdenter.identer.add(identInfo); + PDL_FolkeregisterIdentifikator fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent.status = PDL_IdentStatus.I_BRUK; + fregIdent.type = PDL_IdentType.FNR; + fregIdent.identifikasjonsnummer = '12345678901'; + fregIdent.metadata = new PDL_Metadata(); + fregIdent.metadata.historisk = false; + athos.hentPerson.folkeregisteridentifikator.add(fregIdent); + KafkaPerson3 porthos = createBaseKafkaPerson('1122334455666'); + identInfo = new PDL_IdentInformasjon(); + identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + identInfo.historisk = false; + identInfo.ident = '12345678901'; + porthos.hentIdenter.identer.add(identInfo); + fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent.status = PDL_IdentStatus.I_BRUK; + fregIdent.type = PDL_IdentType.FNR; + fregIdent.identifikasjonsnummer = '12345678901'; + fregIdent.metadata = new PDL_Metadata(); + fregIdent.metadata.historisk = false; + porthos.hentPerson.folkeregisteridentifikator.add(fregIdent); + porthos.hentPerson.sikkerhetstiltak = new List(); + porthos.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); + porthos.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); + porthos.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); + KafkaPerson3 aramis = createBaseKafkaPerson('1122334455999'); + identInfo = new PDL_IdentInformasjon(); + identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + identInfo.historisk = false; + identInfo.ident = '12345678902'; + aramis.hentIdenter.identer.add(identInfo); + fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent.status = PDL_IdentStatus.I_BRUK; + fregIdent.type = PDL_IdentType.FNR; + fregIdent.identifikasjonsnummer = '12345678902'; + fregIdent.metadata = new PDL_Metadata(); + fregIdent.metadata.historisk = false; + aramis.hentPerson.folkeregisteridentifikator.add(fregIdent); + KafkaMessage__c message1 = createKafkaMessage('1122334455111', null); + KafkaMessage__c message2 = createKafkaMessage('1122334455666', athos); + KafkaMessage__c message3 = createKafkaMessage('1122334455333', null); + KafkaMessage__c message4 = createKafkaMessage('1122334455666', porthos); + KafkaMessage__c message5 = createKafkaMessage('1122334455222', null); + KafkaMessage__c message6 = createKafkaMessage('1122334455999', aramis); + // Act + Test.startTest(); + insert new List{ message1, message2, message3, message4, message5, message6 }; + AsyncRequestSchedulable.enqueueAsyncJobs(); + Test.stopTest(); + message1 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message1.Id]; + message2 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message2.Id]; + message3 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message3.Id]; + message4 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message4.Id]; + message5 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message5.Id]; + message6 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message6.Id]; + Assert.areEqual( + KafkaMessageService.STATUS_PROCESSED, + message1.CRM_Status__c, + '' + message1.CRM_ErrorMessage__c + ); + Assert.areEqual( + KafkaMessageService.STATUS_PROCESSED, + message2.CRM_Status__c, + '' + message2.CRM_ErrorMessage__c + ); + Assert.areEqual( + KafkaMessageService.STATUS_PROCESSED, + message3.CRM_Status__c, + '' + message3.CRM_ErrorMessage__c + ); + Assert.areEqual( + KafkaMessageService.STATUS_ERROR, + message4.CRM_Status__c, + '' + message4.CRM_ErrorMessage__c + ); + Assert.areEqual( + KafkaMessageService.STATUS_PROCESSED, + message5.CRM_Status__c, + '' + message5.CRM_ErrorMessage__c + ); + Assert.areEqual( + KafkaMessageService.STATUS_PROCESSED, + message6.CRM_Status__c, + '' + message6.CRM_ErrorMessage__c + ); + Assert.areEqual(1, [SELECT COUNT() FROM Person__c WHERE Name = '12345678901']); + Assert.areEqual(1, [SELECT COUNT() FROM Person__c WHERE Name = '12345678902']); + } + } From 5960628ae1dd580557cfff895dd835cc44d6f16e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 31 Jan 2024 18:52:10 +0100 Subject: [PATCH 033/159] add and fail insertKafkaMessageNpidPerson --- .../KafkaPdlPersondokumentHandlerTest.cls | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index e4cee1f2..2fb130af 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1170,4 +1170,35 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual(1, [SELECT COUNT() FROM Person__c WHERE Name = '12345678902']); } + @isTest + static void insertKafkaMessageNpidPerson() { + KafkaPerson3 kafkaPerson = createBaseKafkaPerson('1122334455666'); + PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); + identInfo.gruppe = PDL_IdentGruppe.NPID; + identInfo.historisk = false; + identInfo.ident = '12345678901'; + kafkaPerson.hentIdenter.identer.add(identInfo); + //kafkaPerson.folkeregisterpersonstatus.clear(); + KafkaMessage__c message = createKafkaMessage('1122334455666', kafkaPerson); + // Act + Test.startTest(); + insert message; + AsyncRequestSchedulable.enqueueAsyncJobs(); + Test.stopTest(); + assertProcessed( + [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message.Id LIMIT 1] + ); + Assert.areEqual(1, [SELECT COUNT() FROM Person__c]); + Person__c person = [ + SELECT FIELDS(STANDARD), INT_ActorId__c, INT_fnr__c, INT_dnr__c, INT_npid__c + FROM Person__c + WHERE INT_actorId__c = '1122334455666' + ]; + Assert.areEqual(null, person.INT_fnr__c, 'Did not expect this value to be set'); + Assert.areEqual('12345678901', person.INT_npid__c, 'Expect this value to be set'); + Assert.areEqual(null, person.INT_dnr__c, 'Did not expect this value to be set'); + Assert.areEqual('12345678901', person.Name, 'Expected NAME to be set'); + Assert.areEqual('1122334455666', person.INT_actorId__c, 'Expected AKTØR ID to be set'); + } + } From c0ef5bdd4ee9b881d3a1eb491908e1c5fb451257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 2 Feb 2024 11:51:17 +0100 Subject: [PATCH 034/159] more descriptive missing ident error message --- .../classes/KafkaPdlPersondokumentHandler.cls | 10 ++++++---- .../classes/KafkaPdlPersondokumentHandlerTest.cls | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index f4e479d2..c63fe1e5 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -683,14 +683,16 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess private static void setIdents(Person__c person, KafkaPerson3 kp) { PDL_IdentInformasjon[] identer = kp.hentIdenter.identer; PDL_Folkeregisteridentifikator[] fregIdenter = kp.hentPerson.folkeregisteridentifikator; - if (identer != null && identer.isEmpty() == false && - fregIdenter != null && - fregIdenter.isEmpty() == false) { + if (identer != null && identer.isEmpty() == false) { person.INT_NPID__c = Pdl_IdentUtility.getIdentsFromList(identer).npid; + } else { + throw new PdlIdentException('Not able to set person idents from Kafka: Missing identer.'); + } + if (fregIdenter != null) { //person.INT_fnr__c = Pdl_IdentUtility.getIdentsFromList(identer).fnr; setFolkeregisterIdents(person, fregIdenter); } else { - throw new PdlIdentException('Not able to set person idents from Kafka'); + throw new PdlIdentException('Not able to set person idents from Kafka: Missing folkeregisteridentifikator.'); } } diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 2fb130af..2cf1f53b 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1195,10 +1195,10 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { WHERE INT_actorId__c = '1122334455666' ]; Assert.areEqual(null, person.INT_fnr__c, 'Did not expect this value to be set'); - Assert.areEqual('12345678901', person.INT_npid__c, 'Expect this value to be set'); + Assert.areEqual('12345678901', person.INT_npid__c, 'Expected this value to be set'); Assert.areEqual(null, person.INT_dnr__c, 'Did not expect this value to be set'); Assert.areEqual('12345678901', person.Name, 'Expected NAME to be set'); - Assert.areEqual('1122334455666', person.INT_actorId__c, 'Expected AKTØR ID to be set'); + Assert.areEqual('1122334455666', person.INT_actorId__c, 'Expected AKTØRID to be set'); } } From 20e3c5e0568f060d47050d48de005330dc2af40d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 6 Feb 2024 14:54:22 +0100 Subject: [PATCH 035/159] add/pass insertKafkaMessageNpidPersonFromNpidToFnr --- .../KafkaPdlPersondokumentHandlerTest.cls | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 2cf1f53b..c9ef1f64 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1201,4 +1201,117 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('1122334455666', person.INT_actorId__c, 'Expected AKTØRID to be set'); } + @isTest + /** + * Check that: + * - person with npid is inserted normally, gets name = npid + * - giving this person a dnr sets name = dnr + * - deprecating the dnr and adding fnr sets name = fnr + */ + static void insertKafkaMessageNpidPersonFromNpidToFnr() { + KafkaPerson3 kafkaPerson = createBaseKafkaPerson('1122334455666'); + PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); + identInfo.gruppe = PDL_IdentGruppe.NPID; + identInfo.historisk = false; + identInfo.ident = '12345678901'; + kafkaPerson.hentIdenter.identer.add(identInfo); + //kafkaPerson.folkeregisterpersonstatus.clear(); + // first message; person with active npid + KafkaMessage__c message1 = createKafkaMessage('1122334455666', kafkaPerson); + identInfo = new PDL_IdentInformasjon(); + identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + identInfo.historisk = false; + identInfo.ident = '52345678901'; + kafkaPerson.hentIdenter.identer.add(identInfo); + PDL_FolkeregisterIdentifikator fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent.identifikasjonsnummer = '52345678901'; + fregIdent.type = PDL_IdentType.DNR; + fregIdent.status = PDL_IdentStatus.I_BRUK; + fregIdent.metadata = new PDL_Metadata(); + fregIdent.metadata.historisk = false; + kafkaPerson.hentPerson.folkeregisteridentifikator.add(fregIdent); + kafkaPerson.hentPerson.folkeregisterpersonstatus.add(new PDL_Folkeregisterpersonstatus()); + kafkaPerson.hentPerson.folkeregisterpersonstatus[0].status = 'bosatt'; + // second message; now also with active freg-ident: dnr + KafkaMessage__c message2 = createKafkaMessage('1122334455666', kafkaPerson); + // deprecate this ident + kafkaPerson.hentIdenter.identer[kafkaPerson.hentIdenter.identer.size() - 1].historisk = true; + kafkaPerson.hentPerson.folkeregisteridentifikator[kafkaPerson.hentPerson.folkeregisteridentifikator.size() - 1].status = PDL_IdentStatus.OPPHOERT; + kafkaPerson.hentPerson.folkeregisteridentifikator[kafkaPerson.hentPerson.folkeregisteridentifikator.size() - 1].metadata.historisk = true; + // and make a new one + identInfo = new PDL_IdentInformasjon(); + identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + identInfo.historisk = false; + identInfo.ident = '11345678901'; + kafkaPerson.hentIdenter.identer.add(identInfo); + fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent.identifikasjonsnummer = '11345678901'; + fregIdent.type = PDL_IdentType.FNR; + fregIdent.status = PDL_IdentStatus.I_BRUK; + fregIdent.metadata = new PDL_Metadata(); + fregIdent.metadata.historisk = false; + kafkaPerson.hentPerson.folkeregisteridentifikator.add(fregIdent); + // third message; deprecated dnr-freg-ident, new fnr-freg-ident + KafkaMessage__c message3 = createKafkaMessage('1122334455666', kafkaPerson); + KafkaMessageService msgService; + Person__c person; + // Act + Test.startTest(); + //Message 1 + insert message1; + msgService = new KafkaMessageService(new List{ message1 }); + msgService.handleMessages(); + assertProcessed( + [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message1.Id LIMIT 1] + ); + Assert.areEqual(1, [SELECT COUNT() FROM Person__c]); + person = [ + SELECT FIELDS(STANDARD), INT_ActorId__c, INT_fnr__c, INT_dnr__c, INT_npid__c + FROM Person__c + WHERE INT_actorId__c = '1122334455666' + ]; + Assert.areEqual('1122334455666', person.INT_actorId__c, 'Expected AKTØR ID to be set'); + Assert.isNull(person.INT_fnr__c, 'Did not expect FNR to be set'); + Assert.areEqual('12345678901', person.INT_npid__c, 'Expected NPID to be set'); + Assert.isNull(person.INT_dnr__c, 'Did not expect DNR to be set'); + Assert.areEqual('12345678901', person.Name, 'Expected NAME to be same as NPID'); + //Message 2 + insert message2; + msgService = new KafkaMessageService(new List{ message2 }); + msgService.handleMessages(); + assertProcessed( + [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message2.Id LIMIT 1] + ); + Assert.areEqual(1, [SELECT COUNT() FROM Person__c]); + person = [ + SELECT FIELDS(STANDARD), INT_ActorId__c, INT_fnr__c, INT_dnr__c, INT_npid__c + FROM Person__c + WHERE INT_actorId__c = '1122334455666' + ]; + Assert.areEqual('1122334455666', person.INT_actorId__c, 'Expected AKTØR ID to be set'); + Assert.isNull(person.INT_fnr__c, 'Did not expect FNR to be set'); + Assert.areEqual('12345678901', person.INT_npid__c, 'Expected NPID to be set'); + Assert.areEqual('52345678901', person.INT_dnr__c, 'Expected DNR to be set'); + Assert.areEqual('52345678901', person.Name, 'Expected NAME to be same as DNR'); + //Message 3 + insert message3; + msgService = new KafkaMessageService(new List{ message3 }); + msgService.handleMessages(); + assertProcessed( + [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message3.Id LIMIT 1] + ); + Assert.areEqual(1, [SELECT COUNT() FROM Person__c]); + person = [ + SELECT FIELDS(STANDARD), INT_ActorId__c, INT_fnr__c, INT_dnr__c, INT_npid__c + FROM Person__c + WHERE INT_actorId__c = '1122334455666' + ]; + Assert.areEqual('1122334455666', person.INT_actorId__c, 'Expected AKTØR ID to be set'); + Assert.areEqual('11345678901', person.INT_fnr__c, 'Expected FNR to be set'); + Assert.areEqual('12345678901', person.INT_npid__c, 'Expected NPID to be set'); + Assert.areEqual('52345678901', person.INT_dnr__c, 'Expect DNR to be set'); + Assert.areEqual('11345678901', person.Name, 'Expected NAME to be same as FNR'); + Test.stopTest(); + } + } From 83df322f6bbe1d3edc22c508e7f082a7d6dd24ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 6 Feb 2024 20:11:37 +0100 Subject: [PATCH 036/159] run and fail mapFieldValuesExcludingAddresses test --- .../pdl-apexTypes/classes/PDL_Doedsfall.cls | 1 + .../pdl-apexTypes/classes/PDL_Foedsel.cls | 1 + .../pdl-apexTypes/classes/PDL_Fullmakt.cls | 5 + .../pdl-apexTypes/classes/PDL_HentPerson.cls | 4 +- .../pdl-apexTypes/classes/PDL_Kjoenn.cls | 1 + .../classes/PDL_Sikkerhetstiltak.cls | 5 + .../PDL_SikkerhetstiltakKontaktperson.cls | 2 + .../classes/PDL_Statsborgerskap.cls | 1 + .../classes/PDL_Telefonnummer.cls | 3 + .../classes/PDL_VergeEllerFullmektig.cls | 4 + .../PDL_VergemaalEllerFremtidsfullmakt.cls | 2 + .../KafkaPdlPersondokumentHandlerTest.cls | 203 ++++++++++++++++++ 12 files changed, 230 insertions(+), 2 deletions(-) diff --git a/force-app/pdl-apexTypes/classes/PDL_Doedsfall.cls b/force-app/pdl-apexTypes/classes/PDL_Doedsfall.cls index 04312e91..ec9375df 100644 --- a/force-app/pdl-apexTypes/classes/PDL_Doedsfall.cls +++ b/force-app/pdl-apexTypes/classes/PDL_Doedsfall.cls @@ -1,5 +1,6 @@ public with sharing class PDL_Doedsfall { + @TestVisible public Date doedsdato{ get;} public PDL_Metadata metadata{ get;} public PDL_Folkeregistermetadata folkeregistermetadata{ get;} diff --git a/force-app/pdl-apexTypes/classes/PDL_Foedsel.cls b/force-app/pdl-apexTypes/classes/PDL_Foedsel.cls index 759156b4..e024573a 100644 --- a/force-app/pdl-apexTypes/classes/PDL_Foedsel.cls +++ b/force-app/pdl-apexTypes/classes/PDL_Foedsel.cls @@ -1,6 +1,7 @@ public with sharing class PDL_Foedsel { public Integer foedselsaar{ get;} + @TestVisible public Date foedselsdato{ get;} public String foedeland{ get;} public String foedested{ get;} diff --git a/force-app/pdl-apexTypes/classes/PDL_Fullmakt.cls b/force-app/pdl-apexTypes/classes/PDL_Fullmakt.cls index 1ea6bd8d..9375ff0d 100644 --- a/force-app/pdl-apexTypes/classes/PDL_Fullmakt.cls +++ b/force-app/pdl-apexTypes/classes/PDL_Fullmakt.cls @@ -1,9 +1,14 @@ public with sharing class PDL_Fullmakt { + @TestVisible public String motpartsPersonident{ get;} + @TestVisible public PDL_FullmaktsRolle motpartsRolle{ get;} + @TestVisible public String[] omraader{ get;} + @TestVisible public Date gyldigFraOgMed{ get;} + @TestVisible public Date gyldigTilOgMed{ get;} public PDL_Metadata metadata{ get;} diff --git a/force-app/pdl-apexTypes/classes/PDL_HentPerson.cls b/force-app/pdl-apexTypes/classes/PDL_HentPerson.cls index d1030a68..1029485a 100644 --- a/force-app/pdl-apexTypes/classes/PDL_HentPerson.cls +++ b/force-app/pdl-apexTypes/classes/PDL_HentPerson.cls @@ -27,6 +27,8 @@ public with sharing class PDL_HentPerson { @TestVisible public PDL_Identitetsgrunnlag[] identitetsgrunnlag{ get;} @TestVisible + public PDL_InnflyttingTilNorge[] innflyttingTilNorge{ get;} + @TestVisible public PDL_Kjoenn[] kjoenn{ get;} @TestVisible public PDL_Kontaktadresse[] kontaktadresse{ get;} @@ -51,8 +53,6 @@ public with sharing class PDL_HentPerson { @TestVisible public PDL_UtenlandskIdentifikasjonsnummer[] utenlandskIdentifikasjonsnummer{ get;} @TestVisible - public PDL_InnflyttingTilNorge[] innflyttingTilNorge{ get;} - @TestVisible public PDL_UtflyttingFraNorge[] utflyttingFraNorge{ get;} @TestVisible public PDL_VergemaalEllerFremtidsfullmakt[] vergemaalEllerFremtidsfullmakt{ get;} diff --git a/force-app/pdl-apexTypes/classes/PDL_Kjoenn.cls b/force-app/pdl-apexTypes/classes/PDL_Kjoenn.cls index 490f3372..678207ba 100644 --- a/force-app/pdl-apexTypes/classes/PDL_Kjoenn.cls +++ b/force-app/pdl-apexTypes/classes/PDL_Kjoenn.cls @@ -1,5 +1,6 @@ public with sharing class PDL_Kjoenn { + @TestVisible public PDL_KjoennType kjoenn{ get;} public PDL_Folkeregistermetadata folkeregistermetadata{ get;} public PDL_Metadata metadata{ get;} diff --git a/force-app/pdl-apexTypes/classes/PDL_Sikkerhetstiltak.cls b/force-app/pdl-apexTypes/classes/PDL_Sikkerhetstiltak.cls index 24415509..a6765d69 100644 --- a/force-app/pdl-apexTypes/classes/PDL_Sikkerhetstiltak.cls +++ b/force-app/pdl-apexTypes/classes/PDL_Sikkerhetstiltak.cls @@ -1,9 +1,14 @@ public with sharing class PDL_Sikkerhetstiltak { + @TestVisible public String tiltakstype{ get;} + @TestVisible public String beskrivelse{ get;} + @TestVisible public PDL_SikkerhetstiltakKontaktperson kontaktperson{ get;} + @TestVisible public Date gyldigFraOgMed{ get;} + @TestVisible public Date gyldigTilOgMed{ get;} public PDL_Metadata metadata{ get;} diff --git a/force-app/pdl-apexTypes/classes/PDL_SikkerhetstiltakKontaktperson.cls b/force-app/pdl-apexTypes/classes/PDL_SikkerhetstiltakKontaktperson.cls index 39d57292..3d5800df 100644 --- a/force-app/pdl-apexTypes/classes/PDL_SikkerhetstiltakKontaktperson.cls +++ b/force-app/pdl-apexTypes/classes/PDL_SikkerhetstiltakKontaktperson.cls @@ -1,6 +1,8 @@ public with sharing class PDL_SikkerhetstiltakKontaktperson { + @TestVisible public String personident{ get;} + @TestVisible public String enhet{ get;} public PDL_SikkerhetstiltakKontaktperson() { diff --git a/force-app/pdl-apexTypes/classes/PDL_Statsborgerskap.cls b/force-app/pdl-apexTypes/classes/PDL_Statsborgerskap.cls index fcd1f2d5..21da43bd 100644 --- a/force-app/pdl-apexTypes/classes/PDL_Statsborgerskap.cls +++ b/force-app/pdl-apexTypes/classes/PDL_Statsborgerskap.cls @@ -1,5 +1,6 @@ public with sharing class PDL_Statsborgerskap { + @TestVisible public String land{ get;} public Date bekreftelsesdato{ get;} public Date gyldigFraOgMed{ get;} diff --git a/force-app/pdl-apexTypes/classes/PDL_Telefonnummer.cls b/force-app/pdl-apexTypes/classes/PDL_Telefonnummer.cls index e3170d93..68fa78c4 100644 --- a/force-app/pdl-apexTypes/classes/PDL_Telefonnummer.cls +++ b/force-app/pdl-apexTypes/classes/PDL_Telefonnummer.cls @@ -1,7 +1,10 @@ public with sharing class PDL_Telefonnummer { + @TestVisible public String landskode{ get;} + @TestVisible public String nummer{ get;} + @TestVisible public Integer prioritet{ get;} public PDL_Metadata metadata{ get;} diff --git a/force-app/pdl-apexTypes/classes/PDL_VergeEllerFullmektig.cls b/force-app/pdl-apexTypes/classes/PDL_VergeEllerFullmektig.cls index c85033a1..af24997f 100644 --- a/force-app/pdl-apexTypes/classes/PDL_VergeEllerFullmektig.cls +++ b/force-app/pdl-apexTypes/classes/PDL_VergeEllerFullmektig.cls @@ -1,8 +1,12 @@ public with sharing class PDL_VergeEllerFullmektig { + @TestVisible public PDL_Personnavn navn{ get;} + @TestVisible public String motpartsPersonident{ get;} + @TestVisible public String omfang{ get;} + @TestVisible public Boolean omfangetErInnenPersonligOmraade{ get;} public PDL_VergeEllerFullmektig() { diff --git a/force-app/pdl-apexTypes/classes/PDL_VergemaalEllerFremtidsfullmakt.cls b/force-app/pdl-apexTypes/classes/PDL_VergemaalEllerFremtidsfullmakt.cls index 9a8c2de6..dd984bd1 100644 --- a/force-app/pdl-apexTypes/classes/PDL_VergemaalEllerFremtidsfullmakt.cls +++ b/force-app/pdl-apexTypes/classes/PDL_VergemaalEllerFremtidsfullmakt.cls @@ -1,6 +1,8 @@ public with sharing class PDL_VergemaalEllerFremtidsfullmakt { + @TestVisible public String type{ get;} + @TestVisible public String embete{ get;} public PDL_VergeEllerFullmektig vergeEllerFullmektig{ get;} public PDL_Folkeregistermetadata folkeregistermetadata{ get;} diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index c9ef1f64..4a4f67ba 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -70,6 +70,65 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { return kp; } + private static Map getPersonAccountByActorIdent() { + Map personByActorIdent = new Map(); + for (Person__c person : [ + SELECT + Id, + Name, + INT_ActorId__c, + INT_AddressDistrictNumber__c, + INT_AddressMunicipalityNumber__c, + INT_Citizenships__c, + INT_Confidential__c, + INT_Coordinates__c, + INT_DateOfBirth__c, + INT_DateOfDeath__c, + INT_DistrictNumber__c, + INT_dnr__c, + INT_FamilyRelations__c, + INT_fnr__c, + INT_FirstName__c, + INT_GTDistrictNumber__c, + INT_GTMunicipalityNumber__c, + INT_GuardianshipOrFuturePowerOfAttorney__c, + INT_IsDeceased__c, + INT_IsNavEmployee__c, + INT_LastName__c, + INT_LastUpdatedFromPDL__c, + INT_LastUpdatedFromKRR__c, + INT_LegalStatus__c, + INT_MaritalRelation__c, + INT_MaritalStatus__c, + INT_MaritalStatusDate__c, + INT_MiddleName__c, + INT_MovedFromCountry__c, + INT_MovedFromPlace__c, + INT_MovedToCountry__c, + INT_MovedToPlace__c, + INT_MunicipalityNumber__c, + INT_npid__c, + INT_Phone1__c, + INT_Phone2__c, + INT_PowerOfAttorney__c, + INT_RegionNumber__c, + INT_ResidentialAddress__c, + INT_ResidentialZipCode__c, + INT_SecurityMeasures__c, + INT_Sex__c, + INT_SpokenLanguageIntepreter__c, + INT_TemporaryAddress__c, + INT_TemporaryCountryCode__c, + INT_TemporaryMunicipalityNumber__c, + INT_TemporaryZipCode__c, + INT_TemporaryCoordinates__c + FROM Person__c + ]) { + personByActorIdent.put(person.INT_ActorId__c, person); + } + return personByActorIdent; + } + @isTest static void testCreatePersonFromPersonDokument() { List kafkaMessages = new List(); @@ -1314,4 +1373,148 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Test.stopTest(); } + /*************************** + * VERIFY THE DATA MAPPING * + **************************/ + + @isTest + static void mapFieldValuesExcludingAddresses() { + KafkaPerson3 kafkaPerson = createBaseKafkaPerson('1122334455666'); + PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); + identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + identInfo.historisk = false; + identInfo.ident = '12345678901'; + kafkaPerson.hentIdenter.identer.add(identInfo); + PDL_FolkeregisterIdentifikator fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent.identifikasjonsnummer = '12345678901'; + fregIdent.type = PDL_IdentType.FNR; + fregIdent.status = PDL_IdentStatus.I_BRUK; + fregIdent.metadata = new PDL_Metadata(); + fregIdent.metadata.historisk = false; + kafkaPerson.hentPerson.folkeregisteridentifikator.add(fregIdent); + PDL_Navn navn = new PDL_Navn(); + navn.fornavn = 'TEST'; + navn.mellomnavn = 'T.'; + kafkaPerson.hentPerson.navn.add(navn); + PDL_Foedsel foedsel = new PDL_Foedsel(); + foedsel.foedselsdato = Date.valueOf('2020-02-25'); + kafkaPerson.hentPerson.foedsel.add(foedsel); + PDL_InnflyttingTilNorge innflytting = new PDL_InnflyttingTilNorge(); + innflytting.fraflyttingsland = 'IND'; + innflytting.fraflyttingsstedIUtlandet = 'Delhi'; + kafkaPerson.hentPerson.innflyttingTilNorge.add(innflytting); + PDL_Sikkerhetstiltak tiltak = new PDL_Sikkerhetstiltak(); + tiltak.beskrivelse = 'Telefonisk utestengelse'; + tiltak.tiltaksType = 'TFUS'; + tiltak.gyldigFraOgMed = Date.valueOf('2020-12-14'); + tiltak.gyldigTilOgMed = Date.valueOf('2020-12-20'); + tiltak.kontaktperson.personident = 'Z000000'; + tiltak.kontaktperson.enhet = '0000'; + kafkaPerson.hentPerson.sikkerhetstiltak.add(tiltak); + PDL_Statsborgerskap statsborgerskap = new PDL_Statsborgerskap(); + statsborgerskap.land = 'NOR'; + kafkaPerson.hentPerson.statsborgerskap.add(statsborgerskap); + PDL_Sivilstand sivilstand = new PDL_Sivilstand(); + sivilstand.type = PDL_Sivilstandstype.GIFT; + sivilstand.gyldigFraOgMed = Date.newInstance(2001, 6, 20); + sivilstand.relatertVedSivilstand = '12345678910'; + kafkaPerson.hentPerson.sivilstand.add(sivilstand); + PDL_Kjoenn kjoenn = new PDL_Kjoenn(); + kjoenn.kjoenn = PDL_KjoennType.MANN; + kafkaPerson.hentPerson.kjoenn.add(kjoenn); + PDL_Doedsfall doedsfall = new PDL_Doedsfall(); + doedsfall.doedsdato = Date.valueOf('2019-01-29'); + // TODO + //doedsfall.master = 'FREG'; + kafkaPerson.hentPerson.doedsfall.add(doedsfall); + PDL_Telefonnummer nummer = new PDL_Telefonnummer(); + nummer.landskode = '+46'; + nummer.nummer = '123456789'; + nummer.prioritet = 2; + kafkaPerson.hentPerson.telefonnummer.add(nummer); + nummer = new PDL_Telefonnummer(); + nummer.landskode = '+47'; + nummer.nummer = '987654321'; + nummer.prioritet = 1; + kafkaPerson.hentPerson.telefonnummer.add(nummer); + PDL_UtflyttingFraNorge utflytting = new PDL_UtflyttingFraNorge(); + utflytting.tilflyttingsland = 'IND'; + utflytting.tilflyttingsstedIUtlandet = 'Delhi'; + kafkaPerson.hentPerson.utflyttingFraNorge.add(utflytting); + // TODO + //kafkaPerson.talesspraaktolk = new List(); + //kafkaPerson.talesspraaktolk.add('NO'); + PDL_Fullmakt fullmakt = new PDL_Fullmakt(); + fullmakt.motpartsRolle = PDL_FullmaktsRolle.FULLMEKTIG; + fullmakt.motpartsPersonident = '12345678910'; + fullmakt.omraader = new List{ 'DAG' }; + fullmakt.gyldigFraOgMed = Date.valueOf('2020-02-14'); + fullmakt.gyldigTilOgMed = Date.valueOf('2020-02-28'); + kafkaPerson.hentPerson.fullmakt.add(fullmakt); + PDL_VergemaalEllerFremtidsfullmakt verge = new PDL_VergemaalEllerFremtidsfullmakt(); + verge.type = 'stadfestetFremtidsfullmakt'; + verge.embete = 'Statsforvalter'; + verge.vergeEllerFullmektig.navn = null; + verge.vergeEllerFullmektig.motpartsPersonident = '12345678910'; + verge.vergeEllerFullmektig.omfang = 'Personlige og/eller økonomiske interesser'; + verge.vergeEllerFullmektig.omfangetErInnenPersonligOmraade = true; + kafkaPerson.hentPerson.vergemaalEllerFremtidsfullmakt.add(verge); + + KafkaMessage__c message = createKafkaMessage('1122334455666', kafkaPerson); + + Test.startTest(); + insert message; + AsyncRequestSchedulable.enqueueAsyncJobs(); + Test.stopTest(); + + assertProcessed( + [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message.Id LIMIT 1] + ); + + Person__c person = getPersonAccountByActorIdent().get('1122334455666'); + + System.assertEquals('1122334455666', person.INT_actorId__c, 'Expected AKTØR ID to be set'); + System.assertEquals('12345678901', person.INT_fnr__c, 'Expected FNR to be set'); + System.assertEquals(null, person.INT_npid__c, 'Expected NPID to be null'); + System.assertEquals(null, person.INT_dnr__c, 'Expect DNR to be null'); + System.assertEquals('12345678901', person.Name, 'Expected NAME to be same as FNR'); + + System.assertEquals('2020-02-25', person.INT_DateOfBirth__c, 'Expected '); + + System.assertEquals('TEST', person.INT_FirstName__c, 'Expected '); + System.assertEquals('T.', person.INT_MiddleName__c, 'Expected '); + System.assertEquals('TESTESEN', person.INT_LastName__c, 'Expected '); + + System.assertEquals('Bosatt', person.INT_LegalStatus__c, 'Expected '); + + System.assertNotEquals(null, person.INT_MovedFromCountry__c, 'Expected '); + System.assertEquals('Delhi', person.INT_MovedFromPlace__c, 'Expected '); + + System.assertEquals('UGRADERT', person.INT_Confidential__c, 'Expected '); + + System.assert(String.isNotBlank(person.INT_SecurityMeasures__c), 'Expected '); + + System.assertEquals('Norge', person.INT_Citizenships__c, 'Expected '); + + System.assertEquals('GIFT', person.INT_MaritalStatus__c, 'Expected '); + System.assertEquals(Date.newInstance(2001, 6, 20), person.INT_MaritalStatusDate__c, 'Expected '); + System.assertEquals('12345678910', person.INT_MaritalRelation__c, 'Expected '); + + System.assertEquals('Mann', person.INT_Sex__c, 'Expected '); + + System.assertEquals(Date.newInstance(2019, 1, 29), person.INT_DateOfDeath__c, 'Expected '); + System.assertEquals(true, person.INT_IsDeceased__c, 'Expected '); + + System.assertEquals('+47987654321', person.INT_Phone1__c, 'Expected '); + System.assertEquals('+46123456789', person.INT_Phone2__c, 'Expected '); + + System.assertNotEquals(null, person.INT_MovedToCountry__c, 'Expected '); + System.assertEquals('Delhi', person.INT_MovedToPlace__c, 'Expected '); + + System.assertEquals('NO', person.INT_SpokenLanguageIntepreter__c, 'Expected '); + + System.assert(String.isNotBlank(person.INT_PowerOfAttorney__c), 'Expected '); + System.assert(String.isNotBlank(person.INT_GuardianshipOrFuturePowerOfAttorney__c), 'Expected '); + } + } From efcbd708a06e2d1dfb8b246d23d8ca1a702d6997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 7 Feb 2024 13:13:26 +0100 Subject: [PATCH 037/159] minor --- .../PDL_VergemaalEllerFremtidsfullmakt.cls | 1 + .../KafkaPdlPersondokumentHandlerTest.cls | 60 ++++++++++++------- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/force-app/pdl-apexTypes/classes/PDL_VergemaalEllerFremtidsfullmakt.cls b/force-app/pdl-apexTypes/classes/PDL_VergemaalEllerFremtidsfullmakt.cls index dd984bd1..e27b8ceb 100644 --- a/force-app/pdl-apexTypes/classes/PDL_VergemaalEllerFremtidsfullmakt.cls +++ b/force-app/pdl-apexTypes/classes/PDL_VergemaalEllerFremtidsfullmakt.cls @@ -4,6 +4,7 @@ public with sharing class PDL_VergemaalEllerFremtidsfullmakt { public String type{ get;} @TestVisible public String embete{ get;} + @TestVisible public PDL_VergeEllerFullmektig vergeEllerFullmektig{ get;} public PDL_Folkeregistermetadata folkeregistermetadata{ get;} public PDL_Metadata metadata{ get;} diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 4a4f67ba..cdb9d412 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -23,46 +23,65 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { insert commonCodes; } + /** + * Helper that lets us avoid initialising every part of a KafkaPerson3, + * PDL_IdentInformasjon, or PDL_HentPerson every time + */ private static KafkaPerson3 createBaseKafkaPerson(String actorId) { KafkaPerson3 kp = new KafkaPerson3(); kp.hentIdenter = new KafkaPerson3.HentIdenter(); kp.hentIdenter.identer = new List(); kp.hentPerson = new PDL_HentPerson(); + // just initialise all the lists. kp.hentPerson.adressebeskyttelse = new List(); kp.hentPerson.bostedsadresse = new List(); - //kp.hentPerson.bostedsadresse.matrikkeladresse = new List(); - //kp.hentPerson.bostedsadresse.ukjentBosted = new List(); - //kp.hentPerson.bostedsadresse.utenlandskAdresse = new List(); - //kp.hentPerson.bostedsadresse.vegadresse = new List(); - //kp.hentPerson.bydelsnummerFraGt = ''; + kp.hentPerson.deltBosted = new List(); + kp.hentPerson.doedfoedtBarn = new List(); kp.hentPerson.doedsfall = new List(); kp.hentPerson.foedsel = new List(); kp.hentPerson.folkeregisteridentifikator = new List(); kp.hentPerson.folkeregisterpersonstatus = new List(); + kp.hentPerson.forelderBarnRelasjon = new List(); + kp.hentPerson.foreldreansvar = new List(); + kp.hentPerson.fullmakt = new List(); + kp.hentPerson.identitetsgrunnlag = new List(); kp.hentPerson.innflyttingTilNorge = new List(); kp.hentPerson.kjoenn = new List(); - //kp.hentPerson.kommunenummerFraGt = ''; + kp.hentPerson.kontaktadresse = new List(); + kp.hentPerson.kontaktinformasjonForDoedsbo = new List(); kp.hentPerson.navn = new List(); + kp.hentPerson.opphold = new List(); kp.hentPerson.oppholdsadresse = new List(); - //kp.hentPerson.oppholdsadresse.matrikkeladresse = new List(); - //kp.hentPerson.oppholdsadresse.ukjentBosted = new List(); - //kp.hentPerson.oppholdsadresse.utenlandskAdresse = new List(); - //kp.hentPerson.oppholdsadresse.vegadresse = new List(); + kp.hentPerson.sikkerhetstiltak = new List(); kp.hentPerson.sivilstand = new List(); kp.hentPerson.statsborgerskap = new List(); kp.hentPerson.telefonnummer = new List(); + kp.hentPerson.tilrettelagtKommunikasjon = new List(); + kp.hentPerson.utenlandskIdentifikasjonsnummer = new List(); kp.hentPerson.utflyttingFraNorge = new List(); - //Default values - //Ident + kp.hentPerson.vergemaalEllerFremtidsfullmakt = new List(); + // no longer necessary? + //kp.hentPerson.bostedsadresse.matrikkeladresse = new List(); + //kp.hentPerson.bostedsadresse.ukjentBosted = new List(); + //kp.hentPerson.bostedsadresse.utenlandskAdresse = new List(); + //kp.hentPerson.bostedsadresse.vegadresse = new List(); + //kp.hentPerson.bydelsnummerFraGt = ''; + //kp.hentPerson.kommunenummerFraGt = ''; + //kp.hentPerson.oppholdsadresse.matrikkeladresse = new List(); + //kp.hentPerson.oppholdsadresse.ukjentBosted = new List(); + //kp.hentPerson.oppholdsadresse.utenlandskAdresse = new List(); + //kp.hentPerson.oppholdsadresse.vegadresse = new List(); + // Default values + // Ident kp.hentIdenter.identer.add(new PDL_IdentInformasjon()); kp.hentIdenter.identer[0].gruppe = PDL_IdentGruppe.AKTORID; kp.hentIdenter.identer[0].historisk = false; kp.hentIdenter.identer[0].ident = actorId; - //Person status + // Person status // isn't there a better way than initializing all of these manually? kp.hentPerson.folkeregisterpersonstatus.add(new PDL_Folkeregisterpersonstatus()); kp.hentPerson.folkeregisterpersonstatus[0].status = 'bosatt'; - //Navn + // Navn kp.hentPerson.navn.add(new PDL_Navn()); kp.hentPerson.navn[0].etternavn = 'TRESTRESEN'; kp.hentPerson.adressebeskyttelse.add(new PDL_Adressebeskyttelse()); @@ -1392,10 +1411,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { fregIdent.metadata = new PDL_Metadata(); fregIdent.metadata.historisk = false; kafkaPerson.hentPerson.folkeregisteridentifikator.add(fregIdent); - PDL_Navn navn = new PDL_Navn(); - navn.fornavn = 'TEST'; - navn.mellomnavn = 'T.'; - kafkaPerson.hentPerson.navn.add(navn); + // surname already provided by createBaseKafkaPerson + kafkaPerson.hentPerson.navn[0].fornavn = 'TREST'; + kafkaPerson.hentPerson.navn[0].mellomnavn = 'T.'; PDL_Foedsel foedsel = new PDL_Foedsel(); foedsel.foedselsdato = Date.valueOf('2020-02-25'); kafkaPerson.hentPerson.foedsel.add(foedsel); @@ -1408,6 +1426,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { tiltak.tiltaksType = 'TFUS'; tiltak.gyldigFraOgMed = Date.valueOf('2020-12-14'); tiltak.gyldigTilOgMed = Date.valueOf('2020-12-20'); + tiltak.kontaktperson = new PDL_SikkerhetstiltakKontaktperson(); tiltak.kontaktperson.personident = 'Z000000'; tiltak.kontaktperson.enhet = '0000'; kafkaPerson.hentPerson.sikkerhetstiltak.add(tiltak); @@ -1454,6 +1473,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { PDL_VergemaalEllerFremtidsfullmakt verge = new PDL_VergemaalEllerFremtidsfullmakt(); verge.type = 'stadfestetFremtidsfullmakt'; verge.embete = 'Statsforvalter'; + verge.vergeEllerFullmektig = new PDL_VergeEllerFullmektig(); verge.vergeEllerFullmektig.navn = null; verge.vergeEllerFullmektig.motpartsPersonident = '12345678910'; verge.vergeEllerFullmektig.omfang = 'Personlige og/eller økonomiske interesser'; @@ -1481,9 +1501,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { System.assertEquals('2020-02-25', person.INT_DateOfBirth__c, 'Expected '); - System.assertEquals('TEST', person.INT_FirstName__c, 'Expected '); + System.assertEquals('TREST', person.INT_FirstName__c, 'Expected '); System.assertEquals('T.', person.INT_MiddleName__c, 'Expected '); - System.assertEquals('TESTESEN', person.INT_LastName__c, 'Expected '); + System.assertEquals('TRESTRESEN', person.INT_LastName__c, 'Expected '); System.assertEquals('Bosatt', person.INT_LegalStatus__c, 'Expected '); From b37eb923b414c8dcd9c27a882d76fdb360ab36e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 7 Feb 2024 13:43:11 +0100 Subject: [PATCH 038/159] map INT_LegalStatus__c --- .../pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index c63fe1e5..380271eb 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -294,11 +294,11 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess person.INT_LastName__c = stringValidator(navn.etternavn); } - /* // folkeregisterpersonstatus - if (kafkaPerson.folkeregisterpersonstatus.size() > 0) { - person.INT_LegalStatus__c = kafkaPerson.folkeregisterpersonstatus[0]; + if (hentPerson.folkeregisterpersonstatus.size() > 0) { + person.INT_LegalStatus__c = hentPerson.folkeregisterpersonstatus[0].status; } + /* // InnflytningTilNorge if (kafkaPerson.innflyttingTilNorge.size() > 0) { From eb9966e2f4bfec83d9c7d9e724b30a17e2fb5a29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 7 Feb 2024 13:55:20 +0100 Subject: [PATCH 039/159] rename System.assertFoo to Assert.foo --- .../KafkaPdlPersondokumentHandlerTest.cls | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index cdb9d412..f43faa2f 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1493,48 +1493,48 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Person__c person = getPersonAccountByActorIdent().get('1122334455666'); - System.assertEquals('1122334455666', person.INT_actorId__c, 'Expected AKTØR ID to be set'); - System.assertEquals('12345678901', person.INT_fnr__c, 'Expected FNR to be set'); - System.assertEquals(null, person.INT_npid__c, 'Expected NPID to be null'); - System.assertEquals(null, person.INT_dnr__c, 'Expect DNR to be null'); - System.assertEquals('12345678901', person.Name, 'Expected NAME to be same as FNR'); + Assert.areEqual('1122334455666', person.INT_actorId__c, 'Expected AKTØR ID to be set'); + Assert.areEqual('12345678901', person.INT_fnr__c, 'Expected FNR to be set'); + Assert.areEqual(null, person.INT_npid__c, 'Expected NPID to be null'); + Assert.areEqual(null, person.INT_dnr__c, 'Expect DNR to be null'); + Assert.areEqual('12345678901', person.Name, 'Expected NAME to be same as FNR'); - System.assertEquals('2020-02-25', person.INT_DateOfBirth__c, 'Expected '); + Assert.areEqual('2020-02-25', person.INT_DateOfBirth__c, 'Expected '); - System.assertEquals('TREST', person.INT_FirstName__c, 'Expected '); - System.assertEquals('T.', person.INT_MiddleName__c, 'Expected '); - System.assertEquals('TRESTRESEN', person.INT_LastName__c, 'Expected '); + Assert.areEqual('TREST', person.INT_FirstName__c, 'Expected '); + Assert.areEqual('T.', person.INT_MiddleName__c, 'Expected '); + Assert.areEqual('TRESTRESEN', person.INT_LastName__c, 'Expected '); - System.assertEquals('Bosatt', person.INT_LegalStatus__c, 'Expected '); + Assert.areEqual('Bosatt', person.INT_LegalStatus__c, 'Expected '); - System.assertNotEquals(null, person.INT_MovedFromCountry__c, 'Expected '); - System.assertEquals('Delhi', person.INT_MovedFromPlace__c, 'Expected '); + Assert.areNotEqual(null, person.INT_MovedFromCountry__c, 'Expected '); + Assert.areEqual('Delhi', person.INT_MovedFromPlace__c, 'Expected '); - System.assertEquals('UGRADERT', person.INT_Confidential__c, 'Expected '); + Assert.areEqual('UGRADERT', person.INT_Confidential__c, 'Expected '); - System.assert(String.isNotBlank(person.INT_SecurityMeasures__c), 'Expected '); + Assert.isTrue(String.isNotBlank(person.INT_SecurityMeasures__c), 'Expected '); - System.assertEquals('Norge', person.INT_Citizenships__c, 'Expected '); + Assert.areEqual('Norge', person.INT_Citizenships__c, 'Expected '); - System.assertEquals('GIFT', person.INT_MaritalStatus__c, 'Expected '); - System.assertEquals(Date.newInstance(2001, 6, 20), person.INT_MaritalStatusDate__c, 'Expected '); - System.assertEquals('12345678910', person.INT_MaritalRelation__c, 'Expected '); + Assert.areEqual('GIFT', person.INT_MaritalStatus__c, 'Expected '); + Assert.areEqual(Date.newInstance(2001, 6, 20), person.INT_MaritalStatusDate__c, 'Expected '); + Assert.areEqual('12345678910', person.INT_MaritalRelation__c, 'Expected '); - System.assertEquals('Mann', person.INT_Sex__c, 'Expected '); + Assert.areEqual('Mann', person.INT_Sex__c, 'Expected '); - System.assertEquals(Date.newInstance(2019, 1, 29), person.INT_DateOfDeath__c, 'Expected '); - System.assertEquals(true, person.INT_IsDeceased__c, 'Expected '); + Assert.areEqual(Date.newInstance(2019, 1, 29), person.INT_DateOfDeath__c, 'Expected '); + Assert.areEqual(true, person.INT_IsDeceased__c, 'Expected '); - System.assertEquals('+47987654321', person.INT_Phone1__c, 'Expected '); - System.assertEquals('+46123456789', person.INT_Phone2__c, 'Expected '); + Assert.areEqual('+47987654321', person.INT_Phone1__c, 'Expected '); + Assert.areEqual('+46123456789', person.INT_Phone2__c, 'Expected '); - System.assertNotEquals(null, person.INT_MovedToCountry__c, 'Expected '); - System.assertEquals('Delhi', person.INT_MovedToPlace__c, 'Expected '); + Assert.areNotEqual(null, person.INT_MovedToCountry__c, 'Expected '); + Assert.areEqual('Delhi', person.INT_MovedToPlace__c, 'Expected '); - System.assertEquals('NO', person.INT_SpokenLanguageIntepreter__c, 'Expected '); + Assert.areEqual('NO', person.INT_SpokenLanguageIntepreter__c, 'Expected '); - System.assert(String.isNotBlank(person.INT_PowerOfAttorney__c), 'Expected '); - System.assert(String.isNotBlank(person.INT_GuardianshipOrFuturePowerOfAttorney__c), 'Expected '); + Assert.isTrue(String.isNotBlank(person.INT_PowerOfAttorney__c), 'Expected '); + Assert.isTrue(String.isNotBlank(person.INT_GuardianshipOrFuturePowerOfAttorney__c), 'Expected '); } } From add069c2b9039a0b76d6b4393396b41f8e85366f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 7 Feb 2024 18:12:15 +0100 Subject: [PATCH 040/159] remove confusing error messages --- .../KafkaPdlPersondokumentHandlerTest.cls | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index f43faa2f..63dbaf31 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1499,42 +1499,42 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual(null, person.INT_dnr__c, 'Expect DNR to be null'); Assert.areEqual('12345678901', person.Name, 'Expected NAME to be same as FNR'); - Assert.areEqual('2020-02-25', person.INT_DateOfBirth__c, 'Expected '); + Assert.areEqual('2020-02-25', person.INT_DateOfBirth__c); - Assert.areEqual('TREST', person.INT_FirstName__c, 'Expected '); - Assert.areEqual('T.', person.INT_MiddleName__c, 'Expected '); - Assert.areEqual('TRESTRESEN', person.INT_LastName__c, 'Expected '); + Assert.areEqual('TREST', person.INT_FirstName__c); + Assert.areEqual('T.', person.INT_MiddleName__c); + Assert.areEqual('TRESTRESEN', person.INT_LastName__c); - Assert.areEqual('Bosatt', person.INT_LegalStatus__c, 'Expected '); + Assert.areEqual('Bosatt', person.INT_LegalStatus__c); - Assert.areNotEqual(null, person.INT_MovedFromCountry__c, 'Expected '); - Assert.areEqual('Delhi', person.INT_MovedFromPlace__c, 'Expected '); + Assert.areNotEqual(null, person.INT_MovedFromCountry__c); + Assert.areEqual('Delhi', person.INT_MovedFromPlace__c); - Assert.areEqual('UGRADERT', person.INT_Confidential__c, 'Expected '); + Assert.areEqual('UGRADERT', person.INT_Confidential__c); - Assert.isTrue(String.isNotBlank(person.INT_SecurityMeasures__c), 'Expected '); + Assert.isTrue(String.isNotBlank(person.INT_SecurityMeasures__c)); - Assert.areEqual('Norge', person.INT_Citizenships__c, 'Expected '); + Assert.areEqual('Norge', person.INT_Citizenships__c); - Assert.areEqual('GIFT', person.INT_MaritalStatus__c, 'Expected '); - Assert.areEqual(Date.newInstance(2001, 6, 20), person.INT_MaritalStatusDate__c, 'Expected '); - Assert.areEqual('12345678910', person.INT_MaritalRelation__c, 'Expected '); + Assert.areEqual('GIFT', person.INT_MaritalStatus__c); + Assert.areEqual(Date.newInstance(2001, 6, 20), person.INT_MaritalStatusDate__c); + Assert.areEqual('12345678910', person.INT_MaritalRelation__c); - Assert.areEqual('Mann', person.INT_Sex__c, 'Expected '); + Assert.areEqual('Mann', person.INT_Sex__c); - Assert.areEqual(Date.newInstance(2019, 1, 29), person.INT_DateOfDeath__c, 'Expected '); - Assert.areEqual(true, person.INT_IsDeceased__c, 'Expected '); + Assert.areEqual(Date.newInstance(2019, 1, 29), person.INT_DateOfDeath__c); + Assert.areEqual(true, person.INT_IsDeceased__c); - Assert.areEqual('+47987654321', person.INT_Phone1__c, 'Expected '); - Assert.areEqual('+46123456789', person.INT_Phone2__c, 'Expected '); + Assert.areEqual('+47987654321', person.INT_Phone1__c); + Assert.areEqual('+46123456789', person.INT_Phone2__c); - Assert.areNotEqual(null, person.INT_MovedToCountry__c, 'Expected '); - Assert.areEqual('Delhi', person.INT_MovedToPlace__c, 'Expected '); + Assert.areNotEqual(null, person.INT_MovedToCountry__c); + Assert.areEqual('Delhi', person.INT_MovedToPlace__c); - Assert.areEqual('NO', person.INT_SpokenLanguageIntepreter__c, 'Expected '); + Assert.areEqual('NO', person.INT_SpokenLanguageIntepreter__c); - Assert.isTrue(String.isNotBlank(person.INT_PowerOfAttorney__c), 'Expected '); - Assert.isTrue(String.isNotBlank(person.INT_GuardianshipOrFuturePowerOfAttorney__c), 'Expected '); + Assert.isTrue(String.isNotBlank(person.INT_PowerOfAttorney__c)); + Assert.isTrue(String.isNotBlank(person.INT_GuardianshipOrFuturePowerOfAttorney__c)); } } From 47ec59b96d48672a9f4fe1f1c045d1a3167558f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 9 Feb 2024 11:35:28 +0100 Subject: [PATCH 041/159] map INT_MovedFromPlace__c --- .../classes/KafkaPdlPersondokumentHandler.cls | 9 ++++----- .../classes/KafkaPdlPersondokumentHandlerTest.cls | 7 +++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 380271eb..e081d042 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -298,17 +298,16 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess if (hentPerson.folkeregisterpersonstatus.size() > 0) { person.INT_LegalStatus__c = hentPerson.folkeregisterpersonstatus[0].status; } - /* // InnflytningTilNorge - if (kafkaPerson.innflyttingTilNorge.size() > 0) { + if (hentPerson.innflyttingTilNorge.size() > 0) { person.INT_MovedFromCountry__c = getCountryIdFromIso( - kafkaPerson.innflyttingTilNorge[kafkaPerson.innflyttingTilNorge.size() - 1].fraflyttingsland + hentPerson.innflyttingTilNorge[hentPerson.innflyttingTilNorge.size() - 1].fraflyttingsland ); - person.INT_MovedFromPlace__c = kafkaPerson.innflyttingTilNorge[kafkaPerson.innflyttingTilNorge.size() - 1] - .fraflyttingsstedIUtlandet; + person.INT_MovedFromPlace__c = hentPerson.innflyttingTilNorge[hentPerson.innflyttingTilNorge.size() - 1].fraflyttingsstedIUtlandet; } + /* // adressebeskyttelse person.INT_Confidential__c = setClearanceLevel(kafkaPerson.adressebeskyttelse); */ diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 63dbaf31..53b60a96 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -6,6 +6,13 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { // record for setting correct Country from Country ISO code List commonCodes = new List(); + Common_Code__c ccIND = new Common_Code__c(); + ccIND.Name = 'India'; + ccIND.CRM_Code_Set__c = 'Landkoder'; + ccIND.CRM_Code__c = 'IND'; + ccIND.CRM_Active__c = true; + commonCodes.add(ccIND); + Common_Code__c ccBEL = new Common_Code__c(); ccBEL.Name = 'BELGIA'; ccBEL.CRM_Code_Set__c = 'Landkoder'; From 06f8dfb89ccbc462022139beecadbb5cb667023f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 9 Feb 2024 13:07:51 +0100 Subject: [PATCH 042/159] map INT_Confidential__c --- .../classes/KafkaPdlPersondokumentHandler.cls | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index e081d042..1b5ce88e 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -307,10 +307,8 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess person.INT_MovedFromPlace__c = hentPerson.innflyttingTilNorge[hentPerson.innflyttingTilNorge.size() - 1].fraflyttingsstedIUtlandet; } - /* // adressebeskyttelse - person.INT_Confidential__c = setClearanceLevel(kafkaPerson.adressebeskyttelse); - */ + person.INT_Confidential__c = setClearanceLevel(hentPerson.adressebeskyttelse); // sikkerhetstiltak person.INT_SecurityMeasures__c = JSON.serialize(kafkaPerson.hentPerson.sikkerhetstiltak); @@ -545,16 +543,17 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess /** * Find the adressebeskyttelse with the strictest security criteria + * If none is specified, default to UGRADERT * @param values * @return The list value with the strictest security criteria */ - private String setClearanceLevel(List values) { + private String setClearanceLevel(List values) { Integer grade = 0; String returnGrade = 'UGRADERT'; - for (String s : values) { - if (ADR_BESKYTTELSES_GRADERING.containsKey(s) && ADR_BESKYTTELSES_GRADERING.get(s) > grade) { - grade = ADR_BESKYTTELSES_GRADERING.get(s); - returnGrade = s; + for (PDL_Adressebeskyttelse beskyttelse : values) { + if (ADR_BESKYTTELSES_GRADERING.containsKey(beskyttelse.gradering.name()) && ADR_BESKYTTELSES_GRADERING.get(beskyttelse.gradering.name()) > grade) { + grade = ADR_BESKYTTELSES_GRADERING.get(beskyttelse.gradering.name()); + returnGrade = beskyttelse.gradering.name(); } } return returnGrade; From 6830f36ff3b830d4c5f62f27155bb2c5f7ef41c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 9 Feb 2024 15:53:29 +0100 Subject: [PATCH 043/159] simplify clearanceLevel until comprehensive test --- .../classes/KafkaPdlPersondokumentHandler.cls | 23 ++++++++----------- .../KafkaPdlPersondokumentHandlerTest.cls | 4 ++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 1b5ce88e..3b9fd0c3 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -6,6 +6,11 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess @TestVisible private static final String PDL_ERROR_STRING = ''; + /** + * Get some transformation into an integer, so information can be hidden + * based on whether or not this integer is greater than some constant. + * Consider doing something more sensible. + */ @TestVisible private static final Map ADR_BESKYTTELSES_GRADERING = new Map{ 'STRENGT_FORTROLIG' => 4, @@ -308,7 +313,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } // adressebeskyttelse - person.INT_Confidential__c = setClearanceLevel(hentPerson.adressebeskyttelse); + person.INT_Confidential__c = clearanceLevel(hentPerson.adressebeskyttelse); // sikkerhetstiltak person.INT_SecurityMeasures__c = JSON.serialize(kafkaPerson.hentPerson.sikkerhetstiltak); @@ -542,21 +547,13 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * Find the adressebeskyttelse with the strictest security criteria - * If none is specified, default to UGRADERT + * Reduce the given list of address protections to just the one with the + * strictest security criteria. If none is specified, default to UGRADERT. * @param values * @return The list value with the strictest security criteria */ - private String setClearanceLevel(List values) { - Integer grade = 0; - String returnGrade = 'UGRADERT'; - for (PDL_Adressebeskyttelse beskyttelse : values) { - if (ADR_BESKYTTELSES_GRADERING.containsKey(beskyttelse.gradering.name()) && ADR_BESKYTTELSES_GRADERING.get(beskyttelse.gradering.name()) > grade) { - grade = ADR_BESKYTTELSES_GRADERING.get(beskyttelse.gradering.name()); - returnGrade = beskyttelse.gradering.name(); - } - } - return returnGrade; + private String clearanceLevel(List values) { + return 'STRENGT_FORTROLIG'; // FIXME rewrite once we have a good test } /** diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 53b60a96..ceec9b62 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1517,8 +1517,6 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areNotEqual(null, person.INT_MovedFromCountry__c); Assert.areEqual('Delhi', person.INT_MovedFromPlace__c); - Assert.areEqual('UGRADERT', person.INT_Confidential__c); - Assert.isTrue(String.isNotBlank(person.INT_SecurityMeasures__c)); Assert.areEqual('Norge', person.INT_Citizenships__c); @@ -1542,6 +1540,8 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.isTrue(String.isNotBlank(person.INT_PowerOfAttorney__c)); Assert.isTrue(String.isNotBlank(person.INT_GuardianshipOrFuturePowerOfAttorney__c)); + + Assert.areEqual('UGRADERT', person.INT_Confidential__c); } } From 3cf7c52e3188bd25e5f8208e34f997e5e7b07009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 9 Feb 2024 16:28:33 +0100 Subject: [PATCH 044/159] map/rewrite INT_Citizenships__c --- .../classes/KafkaPdlPersondokumentHandler.cls | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 3b9fd0c3..72b9415b 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -323,10 +323,12 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess setAddress(person, kafkaPerson); setMunicipalityAndGT(person, kafkaPerson); + */ // statsborgerskap - person.INT_Citizenships__c = crateCitizenshipString(kafkaPerson.statsborgerskap); + person.INT_Citizenships__c = createCitizenshipString(hentPerson.statsborgerskap); + /* // sivilstand if (kafkaPerson.sivilstand.size() > 0) { person.INT_MaritalStatus__c = kafkaPerson.sivilstand[kafkaPerson.sivilstand.size() - 1].type.name(); @@ -652,18 +654,17 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * @param citizenships ISO countrycodes (list) + * @param citizenships PDL_Statsborgerskap (list) * * @return country names joined with ';' */ @TestVisible - private String crateCitizenshipString(List citizenships) { - String citizenshipReturnString = ''; - for (String citizenship : citizenships) { - citizenshipReturnString = citizenshipReturnString + (getCountryNameFromIso(citizenship)) + ';'; + private String createCitizenshipString(List citizenships) { + String[] citizenshipStrings = new List(); + for (PDL_Statsborgerskap citizenship : citizenships) { + citizenshipStrings.add(getCountryNameFromIso(citizenship.land)); } - - return citizenshipReturnString.removeEnd(';'); + return String.join(citizenshipStrings, ';'); } @TestVisible From a9a3ec0bb1210011ddc978f74206b8f46d3b419f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 12 Feb 2024 10:47:29 +0100 Subject: [PATCH 045/159] map INT_MaritalStatus__c along with INT_MaritalStatusDate__c and INT_MaritalRelation__c --- .../classes/KafkaPdlPersondokumentHandler.cls | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 72b9415b..9f67611d 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -328,18 +328,14 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess // statsborgerskap person.INT_Citizenships__c = createCitizenshipString(hentPerson.statsborgerskap); - /* // sivilstand - if (kafkaPerson.sivilstand.size() > 0) { - person.INT_MaritalStatus__c = kafkaPerson.sivilstand[kafkaPerson.sivilstand.size() - 1].type.name(); - // person.INT_MaritalStatusDate__c = dateCreator( - // kafkaPerson.sivilstand[kafkaPerson.sivilstand.size() - 1].gyldigFraOgMed - // ); - person.INT_MaritalStatusDate__c = kafkaPerson.sivilstand[kafkaPerson.sivilstand.size() - 1].gyldigFraOgMed; - person.INT_MaritalRelation__c = kafkaPerson.sivilstand[kafkaPerson.sivilstand.size() - 1] - .relatertVedSivilstand; + if (hentPerson.sivilstand.size() > 0) { + person.INT_MaritalStatus__c = hentPerson.sivilstand[hentPerson.sivilstand.size() - 1].type.name(); + person.INT_MaritalStatusDate__c = hentPerson.sivilstand[hentPerson.sivilstand.size() - 1].gyldigFraOgMed; + person.INT_MaritalRelation__c = hentPerson.sivilstand[hentPerson.sivilstand.size() - 1].relatertVedSivilstand; } + /* // kjoenn if (kafkaPerson.kjoenn.size() > 0) { person.INT_Sex__c = kafkaPerson.kjoenn[0]; From 32c2501e10c611454e81b512554cc81a42c15788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 12 Feb 2024 10:54:07 +0100 Subject: [PATCH 046/159] map INT_Sex__c --- .../pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 9f67611d..90852a66 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -335,11 +335,11 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess person.INT_MaritalRelation__c = hentPerson.sivilstand[hentPerson.sivilstand.size() - 1].relatertVedSivilstand; } - /* // kjoenn - if (kafkaPerson.kjoenn.size() > 0) { - person.INT_Sex__c = kafkaPerson.kjoenn[0]; + if (hentPerson.kjoenn.size() > 0) { + person.INT_Sex__c = hentPerson.kjoenn[hentPerson.kjoenn.size() - 1].kjoenn.name(); } + /* // doedsfall if (kafkaPerson.doedsfall.size() > 0) { person.INT_DateOfDeath__c = getDoedsfall(kafkaPerson.doedsfall); From d90138658819e6a11c25dadc6a9a0a4e18c82559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 12 Feb 2024 16:28:44 +0100 Subject: [PATCH 047/159] save death for when we have better tests --- .../classes/KafkaPdlPersondokumentHandlerTest.cls | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index ceec9b62..14ff8243 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1527,9 +1527,6 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('Mann', person.INT_Sex__c); - Assert.areEqual(Date.newInstance(2019, 1, 29), person.INT_DateOfDeath__c); - Assert.areEqual(true, person.INT_IsDeceased__c); - Assert.areEqual('+47987654321', person.INT_Phone1__c); Assert.areEqual('+46123456789', person.INT_Phone2__c); @@ -1542,6 +1539,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.isTrue(String.isNotBlank(person.INT_GuardianshipOrFuturePowerOfAttorney__c)); Assert.areEqual('UGRADERT', person.INT_Confidential__c); + + Assert.areEqual(Date.newInstance(2019, 1, 29), person.INT_DateOfDeath__c); + Assert.areEqual(true, person.INT_IsDeceased__c); } } From f9b6d14f528b28eb584b96fa6480791409a57caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 12 Feb 2024 16:55:37 +0100 Subject: [PATCH 048/159] map INT_Phone1__c and INT_Phone2__c --- .../pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 8 +++++--- .../classes/KafkaPdlPersondokumentHandlerTest.cls | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 90852a66..17b52c40 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -345,17 +345,19 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess person.INT_DateOfDeath__c = getDoedsfall(kafkaPerson.doedsfall); person.INT_IsDeceased__c = true; //If we got any records return true even if we don't have a date. } + */ // telefonnummer - for (KafkaPerson2.telefonnummer tlf : kafkaPerson.telefonnummer) { - if (tlf.prioritet == '1') { + for (PDL_Telefonnummer tlf : hentPerson.telefonnummer) { + if (tlf.prioritet == 1) { person.INT_Phone1__c = tlf.landskode + tlf.nummer; } - if (tlf.prioritet == '2') { + if (tlf.prioritet == 2) { person.INT_Phone2__c = tlf.landskode + tlf.nummer; } } + /* // utflyttingFraNorge if (kafkaPerson.utflyttingFraNorge.size() > 0) { person.INT_MovedToCountry__c = getCountryIdFromIso( diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 14ff8243..92160526 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1455,12 +1455,12 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { kafkaPerson.hentPerson.doedsfall.add(doedsfall); PDL_Telefonnummer nummer = new PDL_Telefonnummer(); nummer.landskode = '+46'; - nummer.nummer = '123456789'; + nummer.nummer = '0765-43 21 07'; nummer.prioritet = 2; kafkaPerson.hentPerson.telefonnummer.add(nummer); nummer = new PDL_Telefonnummer(); nummer.landskode = '+47'; - nummer.nummer = '987654321'; + nummer.nummer = '987 65 432'; nummer.prioritet = 1; kafkaPerson.hentPerson.telefonnummer.add(nummer); PDL_UtflyttingFraNorge utflytting = new PDL_UtflyttingFraNorge(); @@ -1527,8 +1527,8 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('Mann', person.INT_Sex__c); - Assert.areEqual('+47987654321', person.INT_Phone1__c); - Assert.areEqual('+46123456789', person.INT_Phone2__c); + Assert.areEqual('+47987 65 432', person.INT_Phone1__c); + Assert.areEqual('+460765-43 21 07', person.INT_Phone2__c); Assert.areNotEqual(null, person.INT_MovedToCountry__c); Assert.areEqual('Delhi', person.INT_MovedToPlace__c); From c3e43b78ec3ede1a1d17ecae6a8b4f94824ca4bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 12 Feb 2024 17:16:28 +0100 Subject: [PATCH 049/159] improve assert clarity --- .../classes/KafkaPdlPersondokumentHandlerTest.cls | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 92160526..98a505ca 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1502,8 +1502,8 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('1122334455666', person.INT_actorId__c, 'Expected AKTØR ID to be set'); Assert.areEqual('12345678901', person.INT_fnr__c, 'Expected FNR to be set'); - Assert.areEqual(null, person.INT_npid__c, 'Expected NPID to be null'); - Assert.areEqual(null, person.INT_dnr__c, 'Expect DNR to be null'); + Assert.isNull(person.INT_npid__c, 'Expected NPID to be null'); + Assert.isNull(person.INT_dnr__c, 'Expect DNR to be null'); Assert.areEqual('12345678901', person.Name, 'Expected NAME to be same as FNR'); Assert.areEqual('2020-02-25', person.INT_DateOfBirth__c); @@ -1514,7 +1514,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('Bosatt', person.INT_LegalStatus__c); - Assert.areNotEqual(null, person.INT_MovedFromCountry__c); + Assert.isNotNull(person.INT_MovedFromCountry__c); Assert.areEqual('Delhi', person.INT_MovedFromPlace__c); Assert.isTrue(String.isNotBlank(person.INT_SecurityMeasures__c)); @@ -1530,7 +1530,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('+47987 65 432', person.INT_Phone1__c); Assert.areEqual('+460765-43 21 07', person.INT_Phone2__c); - Assert.areNotEqual(null, person.INT_MovedToCountry__c); + Assert.isNotNull(person.INT_MovedToCountry__c); Assert.areEqual('Delhi', person.INT_MovedToPlace__c); Assert.areEqual('NO', person.INT_SpokenLanguageIntepreter__c); From 84844846a23349b2eaee8a7dd7798e31ca9a48fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 12 Feb 2024 17:21:21 +0100 Subject: [PATCH 050/159] map INT_MovedToCountry__c and INT_MovedToPlace__c --- .../classes/KafkaPdlPersondokumentHandler.cls | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 17b52c40..c881b12b 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -357,16 +357,15 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } } - /* // utflyttingFraNorge - if (kafkaPerson.utflyttingFraNorge.size() > 0) { + if (hentPerson.utflyttingFraNorge.size() > 0) { person.INT_MovedToCountry__c = getCountryIdFromIso( - kafkaPerson.utflyttingFraNorge[kafkaPerson.utflyttingFraNorge.size() - 1].tilflyttingsland + hentPerson.utflyttingFraNorge[hentPerson.utflyttingFraNorge.size() - 1].tilflyttingsland ); - person.INT_MovedToPlace__c = kafkaPerson.utflyttingFraNorge[kafkaPerson.utflyttingFraNorge.size() - 1] - .tilflyttingsstedIUtlandet; + person.INT_MovedToPlace__c = hentPerson.utflyttingFraNorge[hentPerson.utflyttingFraNorge.size() - 1].tilflyttingsstedIUtlandet; } + /* // talesspraaktolk person.INT_SpokenLanguageIntepreter__c = safelyJoinMultiPicklistString(kafkaPerson.talesspraaktolk); From 9d8e988f5795a90d599b29438c5f08b577986ded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 13 Feb 2024 17:28:02 +0100 Subject: [PATCH 051/159] map INT_SpokenLanguageIntepreter__c --- .../classes/PDL_TilrettelagtKommunikasjon.cls | 1 + force-app/pdl-apexTypes/classes/PDL_Tolk.cls | 1 + .../classes/KafkaPdlPersondokumentHandler.cls | 30 ++++++++++++------- .../KafkaPdlPersondokumentHandlerTest.cls | 7 +++-- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/force-app/pdl-apexTypes/classes/PDL_TilrettelagtKommunikasjon.cls b/force-app/pdl-apexTypes/classes/PDL_TilrettelagtKommunikasjon.cls index afd6db95..b0b632c5 100644 --- a/force-app/pdl-apexTypes/classes/PDL_TilrettelagtKommunikasjon.cls +++ b/force-app/pdl-apexTypes/classes/PDL_TilrettelagtKommunikasjon.cls @@ -1,5 +1,6 @@ public with sharing class PDL_TilrettelagtKommunikasjon { + @TestVisible public PDL_Tolk talespraaktolk{ get;} public PDL_Tolk tegnspraaktolk{ get;} public PDL_Metadata metadata{ get;} diff --git a/force-app/pdl-apexTypes/classes/PDL_Tolk.cls b/force-app/pdl-apexTypes/classes/PDL_Tolk.cls index abdfa15d..3b972540 100644 --- a/force-app/pdl-apexTypes/classes/PDL_Tolk.cls +++ b/force-app/pdl-apexTypes/classes/PDL_Tolk.cls @@ -1,5 +1,6 @@ public with sharing class PDL_Tolk { + @TestVisible public String spraak{ get;} public PDL_Tolk() { diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index c881b12b..5e5fd887 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -365,10 +365,13 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess person.INT_MovedToPlace__c = hentPerson.utflyttingFraNorge[hentPerson.utflyttingFraNorge.size() - 1].tilflyttingsstedIUtlandet; } - /* - // talesspraaktolk - person.INT_SpokenLanguageIntepreter__c = safelyJoinMultiPicklistString(kafkaPerson.talesspraaktolk); + // talespraaktolk + // Misleading name, should have been called talespraaktolkbehov + // When non-null, person needs an interpreter, and the non-null value is + // a list of the languages for which an interpreter is required. + person.INT_SpokenLanguageIntepreter__c = interpreterLanguagesString(hentPerson.tilrettelagtKommunikasjon); + /* // fullmakt person.INT_PowerOfAttorney__c = (kafkaPerson.fullmakt == null || kafkaPerson.fullmakt.size() == 0) @@ -501,17 +504,24 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * Safely transform collection into string compatible with multipicklist-fields. - * @param stringsToJoin Collection of strings to join - * @return Null or strings joined with ';' + * Safely transform spoken language interpreter information into string + * compatible with multipicklist-fields. + * @param comms Collection of facilitated communication + * @return null or strings joined with ';' + * TODO: write test for multiple of these */ @TestVisible - private static String safelyJoinMultiPicklistString(List stringsToJoin) { - if (stringsToJoin == null || stringsToJoin.size() == 0) { + private static String interpreterLanguagesString(PDL_TilrettelagtKommunikasjon[] comms) { + String[] interpreterLanguages = new List(); + if (comms == null || comms.size() == 0) { return null; - } else { - return String.join(stringsToJoin, ';'); } + for (PDL_TilrettelagtKommunikasjon comm : comms) { + if (comm.talespraaktolk != null) { + interpreterLanguages.add(comm.talespraaktolk.spraak); + } + } + return String.join(interpreterLanguages, ';'); } /** diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 98a505ca..c1fb1daa 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1467,9 +1467,10 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { utflytting.tilflyttingsland = 'IND'; utflytting.tilflyttingsstedIUtlandet = 'Delhi'; kafkaPerson.hentPerson.utflyttingFraNorge.add(utflytting); - // TODO - //kafkaPerson.talesspraaktolk = new List(); - //kafkaPerson.talesspraaktolk.add('NO'); + PDL_TilrettelagtKommunikasjon kom = new PDL_TilrettelagtKommunikasjon(); + kom.talespraaktolk = new PDL_Tolk(); + kom.talespraaktolk.spraak = 'NO'; + kafkaPerson.hentPerson.tilrettelagtKommunikasjon.add(kom); PDL_Fullmakt fullmakt = new PDL_Fullmakt(); fullmakt.motpartsRolle = PDL_FullmaktsRolle.FULLMEKTIG; fullmakt.motpartsPersonident = '12345678910'; From 536924cc5fa2d0f47e4144cde16f449e6165e30a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 14 Feb 2024 10:31:00 +0100 Subject: [PATCH 052/159] map INT_PowerOfAttorney__c --- .../pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 5e5fd887..4f099e6f 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -371,13 +371,13 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess // a list of the languages for which an interpreter is required. person.INT_SpokenLanguageIntepreter__c = interpreterLanguagesString(hentPerson.tilrettelagtKommunikasjon); - /* // fullmakt - person.INT_PowerOfAttorney__c = (kafkaPerson.fullmakt == null || - kafkaPerson.fullmakt.size() == 0) + person.INT_PowerOfAttorney__c = (hentPerson.fullmakt == null || + hentPerson.fullmakt.size() == 0) ? null - : JSON.serialize(kafkaPerson.fullmakt); + : JSON.serialize(hentPerson.fullmakt); + /* // vergemaalEllerFremtidsfullmakt person.INT_GuardianshipOrFuturePowerOfAttorney__c = (kafkaPerson.vergemaalEllerFremtidsfullmakt == null || kafkaPerson.vergemaalEllerFremtidsfullmakt.size() == 0) From 2e66732d0462df1a9fbeb3323b8fe3ab3043f25d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 14 Feb 2024 11:57:33 +0100 Subject: [PATCH 053/159] substitute more specific tests for "not null" ones --- .../pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index c1fb1daa..34d27246 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1518,7 +1518,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.isNotNull(person.INT_MovedFromCountry__c); Assert.areEqual('Delhi', person.INT_MovedFromPlace__c); - Assert.isTrue(String.isNotBlank(person.INT_SecurityMeasures__c)); + Assert.areEqual('[{"tiltakstype":"TFUS","metadata":null,"kontaktperson":{"personident":"Z000000","enhet":"0000"},"gyldigTilOgMed":"2020-12-20","gyldigFraOgMed":"2020-12-14","beskrivelse":"Telefonisk utestengelse"}]', person.INT_SecurityMeasures__c); Assert.areEqual('Norge', person.INT_Citizenships__c); @@ -1536,7 +1536,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('NO', person.INT_SpokenLanguageIntepreter__c); - Assert.isTrue(String.isNotBlank(person.INT_PowerOfAttorney__c)); + Assert.areEqual('[{"omraader":["DAG"],"motpartsRolle":"FULLMEKTIG","motpartsPersonident":"12345678910","metadata":null,"gyldigTilOgMed":"2020-02-28","gyldigFraOgMed":"2020-02-14"}]', person.INT_PowerOfAttorney__c); Assert.isTrue(String.isNotBlank(person.INT_GuardianshipOrFuturePowerOfAttorney__c)); Assert.areEqual('UGRADERT', person.INT_Confidential__c); From 765de1aef18b3d2839c0ce1f79d839cad6b1c5ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 14 Feb 2024 12:00:23 +0100 Subject: [PATCH 054/159] map INT_GuardianshipOrFuturePowerOfAttorney__c --- .../pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 4f099e6f..f86facb4 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -377,13 +377,13 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess ? null : JSON.serialize(hentPerson.fullmakt); - /* // vergemaalEllerFremtidsfullmakt - person.INT_GuardianshipOrFuturePowerOfAttorney__c = (kafkaPerson.vergemaalEllerFremtidsfullmakt == null || - kafkaPerson.vergemaalEllerFremtidsfullmakt.size() == 0) + person.INT_GuardianshipOrFuturePowerOfAttorney__c = (hentPerson.vergemaalEllerFremtidsfullmakt == null || + hentPerson.vergemaalEllerFremtidsfullmakt.size() == 0) ? null - : JSON.serialize(kafkaPerson.vergemaalEllerFremtidsfullmakt); + : JSON.serialize(hentPerson.vergemaalEllerFremtidsfullmakt); + /* // Ensure that a System User is set as Owner if even if message processing is manually retried by an administrator user if (KafkaIntegrationCustomSetting.integrationUserId != null) { person.OwnerId = KafkaIntegrationCustomSetting.integrationUserId; From d8a5de8bd6e75fddd6a2087f659456dafd5ae051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 14 Feb 2024 12:03:59 +0100 Subject: [PATCH 055/159] specify value of INT_GuardianshipOrFuturePowerO... --- .../pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 34d27246..332eb843 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1537,7 +1537,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('NO', person.INT_SpokenLanguageIntepreter__c); Assert.areEqual('[{"omraader":["DAG"],"motpartsRolle":"FULLMEKTIG","motpartsPersonident":"12345678910","metadata":null,"gyldigTilOgMed":"2020-02-28","gyldigFraOgMed":"2020-02-14"}]', person.INT_PowerOfAttorney__c); - Assert.isTrue(String.isNotBlank(person.INT_GuardianshipOrFuturePowerOfAttorney__c)); + Assert.areEqual('[{"vergeEllerFullmektig":{"omfangetErInnenPersonligOmraade":true,"omfang":"Personlige og/eller økonomiske interesser","navn":null,"motpartsPersonident":"12345678910"},"type":"stadfestetFremtidsfullmakt","metadata":null,"folkeregistermetadata":null,"embete":"Statsforvalter"}]', person.INT_GuardianshipOrFuturePowerOfAttorney__c); Assert.areEqual('UGRADERT', person.INT_Confidential__c); From 3e63152a09ef3ea8692422efb5b6ff35be90782f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 14 Feb 2024 17:45:28 +0100 Subject: [PATCH 056/159] clarify person ident error --- force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index f86facb4..86ff1435 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -751,7 +751,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } person.Name = (String.isNotBlank(flkId)) ? flkId : ((String.isNotBlank(npId) ? npId : null)); if (String.isBlank(person.Name)) - throw new PdlIdentException('Not able to set any person idents from Kafka'); + throw new PdlIdentException('Unable to set either folkeregisterident or NPID from Kafka'); } /** From e1c53a7a9493f3701a8b48aa98badbe34669b07a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 14 Feb 2024 17:57:44 +0100 Subject: [PATCH 057/159] comprehensive test and fix for INT_Confidential__c --- .../classes/KafkaPdlPersondokumentHandler.cls | 12 +++- .../KafkaPdlPersondokumentHandlerTest.cls | 64 +++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 86ff1435..5f5013ad 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -562,7 +562,17 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * @return The list value with the strictest security criteria */ private String clearanceLevel(List values) { - return 'STRENGT_FORTROLIG'; // FIXME rewrite once we have a good test + Integer grade, maxGrade = 0; + String gradeAsString, returnGrade = 'UGRADERT'; + for (PDL_Adressebeskyttelse protection : values) { + gradeAsString = protection.gradering.name(); + grade = ADR_BESKYTTELSES_GRADERING.get(gradeAsString); + if (grade > maxGrade) { + maxGrade = grade; + returnGrade = gradeAsString; + } + } + return returnGrade; } /** diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 332eb843..1e3cf64e 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -96,6 +96,19 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { return kp; } + /** + * As createBaseKafkaPerson(String), but also initialize with a folkeregisterident + */ + private static KafkaPerson3 createBaseKafkaPerson(String actorId, String fregId) { + KafkaPerson3 kp = createBaseKafkaPerson(actorId); + kp.hentIdenter.identer.add(new PDL_IdentInformasjon()); + Integer i = kp.hentIdenter.identer.size() - 1; + kp.hentIdenter.identer[i].ident = fregId; + kp.hentIdenter.identer[i].historisk = false; + kp.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + return kp; + } + private static Map getPersonAccountByActorIdent() { Map personByActorIdent = new Map(); for (Person__c person : [ @@ -1545,4 +1558,55 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual(true, person.INT_IsDeceased__c); } + /******************** + * OTHER UNIT TESTS * + *******************/ + + /** + * Ensure that persons are assigned the highest possible confidentiality + * based on all their address protections. + */ + @isTest + static void testHighestGradeApplies() { + PDL_Adressebeskyttelse ungraded = new PDL_Adressebeskyttelse(); + ungraded.gradering = PDL_AdressebeskyttelseGradering.UGRADERT; + PDL_Adressebeskyttelse confidential = new PDL_Adressebeskyttelse(); + confidential.gradering = PDL_AdressebeskyttelseGradering.FORTROLIG; + PDL_Adressebeskyttelse strictlyConfidential = new PDL_Adressebeskyttelse(); + strictlyConfidential.gradering = PDL_AdressebeskyttelseGradering.STRENGT_FORTROLIG; + PDL_Adressebeskyttelse strictConfAbroad = new PDL_Adressebeskyttelse(); + strictConfAbroad.gradering = PDL_AdressebeskyttelseGradering.STRENGT_FORTROLIG_UTLAND; + KafkaPerson3 fiferPig = createBaseKafkaPerson('8849688496884', '88496884968'); + KafkaPerson3 fiddlerPig = createBaseKafkaPerson('8154968154968', '81549681549'); + KafkaPerson3 practicalPig = createBaseKafkaPerson('9471759694717', '94717596947'); + KafkaPerson3 bigBadWolf = createBaseKafkaPerson('9691858969185', '96918589691'); + // strip existing protection, empty list should default to UGRADERT + bigBadWolf.hentPerson.adressebeskyttelse = new List(); + // add protection + fiddlerPig.hentPerson.adressebeskyttelse.add(confidential); + fiddlerPig.hentPerson.adressebeskyttelse.add(strictConfAbroad); + practicalPig.hentPerson.adressebeskyttelse.add(strictConfAbroad); + practicalPig.hentPerson.adressebeskyttelse.add(strictlyConfidential); + practicalPig.hentPerson.adressebeskyttelse.add(confidential); + // send, receive, test + KafkaMessage__c message1 = createKafkaMessage('8849688496884', fiferPig); + KafkaMessage__c message2 = createKafkaMessage('8154968154968', fiddlerPig); + KafkaMessage__c message3 = createKafkaMessage('9471759694717', practicalPig); + KafkaMessage__c message4 = createKafkaMessage('9691858969185', bigBadWolf); + Test.startTest(); + insert new List{ message1, message2, message3, message4 }; + AsyncRequestSchedulable.enqueueAsyncJobs(); + Test.stopTest(); + KafkaMessage__c[] wtf = [SELECT Id, CRM_Key__c, CRM_Status__c, CRM_ErrorMessage__c from KafkaMessage__c]; + Person__c[] all = [SELECT Id, INT_ActorId__c, INT_Confidential__c from Person__c]; + Integer n = [SELECT COUNT() from Person__c]; + Person__c fiferPerson = [SELECT Id, INT_Confidential__c from Person__c where INT_ActorId__c = '8849688496884'][0]; + Person__c fiddlerPerson = [SELECT Id, INT_Confidential__c from Person__c where INT_ActorId__c = '8154968154968'][0]; + Person__c practicalPerson = [SELECT Id, INT_Confidential__c from Person__c where INT_ActorId__c = '9471759694717'][0]; + Person__c bigBadPerson = [SELECT Id, INT_Confidential__c from Person__c where INT_ActorId__c = '9691858969185'][0]; + Assert.areEqual('UGRADERT', fiferPerson.INT_Confidential__c); + Assert.areEqual('STRENGT_FORTROLIG_UTLAND', fiddlerPerson.INT_Confidential__c); + Assert.areEqual('STRENGT_FORTROLIG', practicalPerson.INT_Confidential__c); + Assert.areEqual('UGRADERT', bigBadPerson.INT_Confidential__c); + } } From 9ae0716b109f7b769ffef8cb25bb6fbf99d54e28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 14 Feb 2024 19:03:11 +0100 Subject: [PATCH 058/159] test for error when passing bad grading --- .../classes/KafkaPdlPersondokumentHandler.cls | 17 ++++++++++--- .../KafkaPdlPersondokumentHandlerTest.cls | 25 +++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 5f5013ad..15b8f414 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -31,6 +31,11 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess private LoggerUtility logger; + /** + * Process messages. Warn or error according to some criteria on which I'm + * not entirely clear yet. Any explicitly raised PdlIdentException seems to + * raise an error. + */ public void processMessages(List messages) { logger = new LoggerUtility('PDL'); Map personMap = new Map(); @@ -91,7 +96,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess messageList.add(messageMap.get(actorId)); } // Errors from DML will set all messages to failed. - // try { List urList = Database.upsert(personList, Person__c.INT_ActorId__c, false); for (Integer i = 0; i < urList.size(); i++) { if (false == urList[i].isSuccess()) { @@ -245,7 +249,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess INT_LastUpdatedFromPDL__c = message.createdDate ); - //If tombstone and no payload, clear data for person except idents. + // If tombstone and no payload, clear data for person except idents. if (true == person.INT_IsHasTombstone__c && String.isBlank(message.CRM_Value__c)) { emptyTombstonePerson(person); return person; @@ -254,7 +258,14 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess emptyPersonFieldValues(person); // why is this necessary? String decodedValue = KafkaMessageUtils.base64ULSafeDecode(message.CRM_Value__c).toString(); - KafkaPerson3 kafkaPerson = KafkaPerson3.parse(decodedValue); + // Fail loudly when deserialization goes wrong. + KafkaPerson3 kafkaPerson; + try { + kafkaPerson = KafkaPerson3.parse(decodedValue); + } catch (JSONException e) { + throw new PdlIdentException('Failed to parse kafka person: ' + + e.getTypeName() + ': ' + e.getMessage() + ' (' + e.getLineNumber() + ')'); + } //validateListSizes(kafkaPerson); person = mapFieldValues(person, kafkaPerson); diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 1e3cf64e..87485e6e 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1609,4 +1609,29 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('STRENGT_FORTROLIG', practicalPerson.INT_Confidential__c); Assert.areEqual('UGRADERT', bigBadPerson.INT_Confidential__c); } + + /** + * Ensure error is thrown on unknown address protection. + */ + @isTest + static void testUnknownAddressProtection() { + List kafkaMessages = new List(); + kafkaMessages.add( + new KafkaMessage__c( + CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Key__c = '9471759694717', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"hentPerson":{"vergemaalEllerFremtidsfullmakt":[],"utflyttingFraNorge":[],"utenlandskIdentifikasjonsnummer":[],"tilrettelagtKommunikasjon":[],"telefonnummer":[],"statsborgerskap":[],"sivilstand":[],"sikkerhetstiltak":[],"oppholdsadresse":[],"opphold":[],"navn":[{"originaltNavn":null,"metadata":null,"mellomnavn":null,"gyldigFraOgMed":null,"fornavn":null,"forkortetNavn":null,"folkeregistermetadata":null,"etternavn":"TRESTRESEN"}],"kontaktinformasjonForDoedsbo":[],"kontaktadresse":[],"kjoenn":[],"innflyttingTilNorge":[],"identitetsgrunnlag":[],"fullmakt":[],"foreldreansvar":[],"forelderBarnRelasjon":[],"folkeregisterpersonstatus":[{"status":"bosatt","metadata":null,"forenkletStatus":null,"folkeregistermetadata":null}],"folkeregisteridentifikator":[],"foedsel":[],"falskIdentitet":null,"doedsfall":[],"doedfoedtBarn":[],"deltBosted":[],"bostedsadresse":[],"adressebeskyttelse":[{"metadata":null,"gradering":"LOLGRADERT","folkeregistermetadata":null},{"metadata":null,"gradering":"STRENGT_FORTROLIG_UTLAND","folkeregistermetadata":null},{"metadata":null,"gradering":"STRENGT_FORTROLIG","folkeregistermetadata":null},{"metadata":null,"gradering":"FORTROLIG","folkeregistermetadata":null}]},"hentIdenter":{"identer":[{"ident":"9471759694717","historisk":false,"gruppe":"AKTORID"},{"ident":"94717596947","historisk":false,"gruppe":"FOLKEREGISTERIDENT"}]}}')), + CRM_Status__c = KafkaMessageService.STATUS_PENDING + ) + ); + Test.startTest(); + KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); + handler.processMessages(kafkaMessages); + Assert.areEqual( + KafkaMessageService.STATUS_ERROR, + kafkaMessages[0].CRM_Status__c, + '' + kafkaMessages[0].CRM_ErrorMessage__c + ); + Test.stopTest(); + } } From 1edfa51d49a788f9becd68d2ed48f80277ed91c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 16 Feb 2024 15:40:21 +0100 Subject: [PATCH 059/159] minor --- .../pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 87485e6e..97209ab2 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -956,7 +956,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { * Create a message similar to one we would receive via Kafka. Note that * JSON.serialize(null) correctly becomes the string "null", however, the * value denoting a tombstone is not the base64 encoding of this string, but - * simply null. Take this into account. + * simply null. (Liable to change, perhaps to the empty string.) */ private static KafkaMessage__c createKafkaMessage( String aktorId, From 8dbcb4445c4a90d3be809c1bc9be3931f2013766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 20 Feb 2024 19:26:33 +0100 Subject: [PATCH 060/159] be explicit: System.Test rather than Test --- .../KafkaPdlPersondokumentHandlerTest.cls | 88 +++++++++---------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 97209ab2..d4f26cbe 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -495,12 +495,12 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { CRM_Status__c = KafkaMessageService.STATUS_PENDING ) ); - Test.startTest(); + System.Test.startTest(); KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); handler.processMessages(kafkaMessages); List pl = [SELECT Id from Person__c where INT_ActorId__c = '2594819806563']; Assert.areEqual(1, pl.size(), 'Expected one person inserted.'); - Test.stopTest(); + System.Test.stopTest(); } @isTest @@ -514,13 +514,13 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { CRM_Status__c = KafkaMessageService.STATUS_PENDING ) ); - Test.startTest(); + System.Test.startTest(); Integer numPersonsBefore = [select id from person__c].size(); KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); handler.processMessages(kafkaMessages); Assert.areEqual(numPersonsBefore, [select id from person__c].size(), 'Expected none inserted.'); - Test.stopTest(); + System.Test.stopTest(); } /******************************************* @@ -558,14 +558,14 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { kPerson.hentIdenter.identer[i].historisk = true; kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; Person__c person = new Person__c(); - Test.startTest(); + System.Test.startTest(); KafkaPdlPersondokumentHandler.setName(person, kPerson.hentIdenter); Assert.areEqual('12345678901', person.Name, 'Expected non historisk FOLKEREGISTERIDENT'); person = new Person__c(); kPerson.hentIdenter.identer[fregIndex].historisk = true; KafkaPdlPersondokumentHandler.setName(person, kPerson.hentIdenter); Assert.areEqual('12345678911', person.Name, 'Expected non historisk NPID'); - Test.stopTest(); + System.Test.stopTest(); } @IsTest @@ -596,7 +596,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { kPerson.hentIdenter.identer[i].historisk = true; kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; Person__c person = new Person__c(); - Test.startTest(); + System.Test.startTest(); try { KafkaPdlPersondokumentHandler.setName(person, kPerson.hentIdenter); Assert.fail('No exception thrown'); @@ -605,7 +605,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { } catch (Exception e) { Assert.fail('Did not catch the correct exception'); } - Test.stopTest(); + System.Test.stopTest(); } @IsTest @@ -645,9 +645,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { fregIdent.metadata.historisk = true; kPerson.hentPerson.folkeregisteridentifikator.add(fregIdent); Person__c person = new Person__c(); - Test.startTest(); + System.Test.startTest(); KafkaPdlPersondokumentHandler.setIdents(person, kPerson); - Test.stopTest(); + System.Test.stopTest(); Assert.areEqual(null, person.INT_ACTORID__c, 'Expected AKTORID to be null'); Assert.areEqual('12345678901', person.INT_FNR__c, 'Expected FNR to be set'); Assert.areEqual('12345678911', person.INT_NPID__c, 'Expect NPID to be set'); @@ -680,9 +680,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; msg.CRM_Key__c = '1000012345678'; msg.CRM_Value__c = 'e30K'; // empty dict: nonnull, so tombstone is false - Test.startTest(); + System.Test.startTest(); new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg }); - Test.stopTest(); + System.Test.stopTest(); Assert.areEqual(KafkaMessageService.STATUS_WARNING, msg.CRM_Status__c, 'Expected the status to be set to warning'); } @@ -709,9 +709,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; msg.CRM_Key__c = '1000012345678'; msg.CRM_Value__c = 'e30K'; // {} - Test.startTest(); + System.Test.startTest(); new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg }); - Test.stopTest(); + System.Test.stopTest(); Assert.areEqual(KafkaMessageService.STATUS_PENDING, msg.CRM_Status__c, 'Expected the status to be the same'); } @@ -738,9 +738,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; msg.CRM_Key__c = '1000012345678'; msg.CRM_Value__c = 'e30K'; // {} - Test.startTest(); + System.Test.startTest(); new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg }); - Test.stopTest(); + System.Test.stopTest(); Assert.areEqual(KafkaMessageService.STATUS_PENDING, msg.CRM_Status__c, 'Expected the status to be the same'); } @@ -761,9 +761,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; msg.CRM_Key__c = '1000012345678'; msg.CRM_Value__c = 'e30K'; // {} - Test.startTest(); + System.Test.startTest(); new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg }); - Test.stopTest(); + System.Test.stopTest(); Assert.areEqual(KafkaMessageService.STATUS_PENDING, msg.CRM_Status__c, 'Expected the status to be the same'); } @@ -818,9 +818,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { msg4.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; msg4.CRM_Key__c = '1000012345678'; msg4.CRM_Value__c = 'e30K'; // {} - Test.startTest(); + System.Test.startTest(); new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg1, msg2, msg3, msg4 }); - Test.stopTest(); + System.Test.stopTest(); Assert.areEqual(KafkaMessageService.STATUS_PENDING, msg1.CRM_Status__c, 'Expected the status to be processed'); Assert.areEqual(KafkaMessageService.STATUS_PENDING, msg2.CRM_Status__c, @@ -863,9 +863,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { msg2.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; msg2.CRM_Key__c = '1000012345678'; // CRM_Value__c is null - Test.startTest(); + System.Test.startTest(); new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg1, msg2 }); - Test.stopTest(); + System.Test.stopTest(); Assert.areEqual(KafkaMessageService.STATUS_WARNING, msg1.CRM_Status__c, 'Expected msg1 status to be warning'); Assert.areEqual(KafkaMessageService.STATUS_PENDING, msg2.CRM_Status__c, @@ -888,9 +888,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { msg1.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; msg1.CRM_Key__c = '1000012345678'; // CRM_Value__c is null - Test.startTest(); + System.Test.startTest(); new KafkaPdlPersondokumentHandler().checkLastUpdatedAndTombStones(new List{ msg1 }); - Test.stopTest(); + System.Test.stopTest(); Assert.areEqual(KafkaMessageService.STATUS_PROCESSED, msg1.CRM_Status__c, 'Expected the status to be processed' ); @@ -921,11 +921,11 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { // Verify that we have only one Account Assert.areEqual(1, [SELECT COUNT() FROM Person__c]); // Act - Test.startTest(); + System.Test.startTest(); insert kafkaMessages; System.debug([SELECT Id, CRM_Topic__c, CRM_Key__c, CRM_ErrorMessage__c FROM KafkaMessage__c]); AsyncRequestSchedulable.enqueueAsyncJobs(); - Test.stopTest(); + System.Test.stopTest(); System.debug([SELECT Id, CRM_Topic__c, CRM_Key__c, CRM_ErrorMessage__c FROM KafkaMessage__c]); // Assert that 1 Person Account has been inserted Assert.areEqual(1, [SELECT COUNT() FROM Person__c]); @@ -1006,10 +1006,10 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { // Verify that we don't have any Person__c records Assert.areEqual(0, [SELECT COUNT() FROM Person__c]); // Act - Test.startTest(); + System.Test.startTest(); insert message; AsyncRequestSchedulable.enqueueAsyncJobs(); - Test.stopTest(); + System.Test.stopTest(); assertProcessed( [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message.Id LIMIT 1] ); @@ -1064,10 +1064,10 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { KafkaMessage__c message3 = createKafkaMessage('1122334455666', porthos); KafkaMessage__c message4 = createKafkaMessage('1122334455666', null); // Act - Test.startTest(); + System.Test.startTest(); insert new List{ message1, message2, message3, message4 }; AsyncRequestSchedulable.enqueueAsyncJobs(); - Test.stopTest(); + System.Test.stopTest(); message1 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message1.Id]; message2 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message2.Id]; message3 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message3.Id]; @@ -1137,10 +1137,10 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { KafkaMessage__c message2 = createKafkaMessage('1122334455666', laurel); KafkaMessage__c message3 = createKafkaMessage('1122334455666', hardy); // Act - Test.startTest(); + System.Test.startTest(); insert new List{ message1, message2, message3 }; AsyncRequestSchedulable.enqueueAsyncJobs(); - Test.stopTest(); + System.Test.stopTest(); message1 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message1.Id]; message2 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message2.Id]; message3 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message3.Id]; @@ -1224,10 +1224,10 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { KafkaMessage__c message5 = createKafkaMessage('1122334455222', null); KafkaMessage__c message6 = createKafkaMessage('1122334455999', aramis); // Act - Test.startTest(); + System.Test.startTest(); insert new List{ message1, message2, message3, message4, message5, message6 }; AsyncRequestSchedulable.enqueueAsyncJobs(); - Test.stopTest(); + System.Test.stopTest(); message1 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message1.Id]; message2 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message2.Id]; message3 = [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message3.Id]; @@ -1279,10 +1279,10 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { //kafkaPerson.folkeregisterpersonstatus.clear(); KafkaMessage__c message = createKafkaMessage('1122334455666', kafkaPerson); // Act - Test.startTest(); + System.Test.startTest(); insert message; AsyncRequestSchedulable.enqueueAsyncJobs(); - Test.stopTest(); + System.Test.stopTest(); assertProcessed( [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message.Id LIMIT 1] ); @@ -1354,7 +1354,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { KafkaMessageService msgService; Person__c person; // Act - Test.startTest(); + System.Test.startTest(); //Message 1 insert message1; msgService = new KafkaMessageService(new List{ message1 }); @@ -1409,7 +1409,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('12345678901', person.INT_npid__c, 'Expected NPID to be set'); Assert.areEqual('52345678901', person.INT_dnr__c, 'Expect DNR to be set'); Assert.areEqual('11345678901', person.Name, 'Expected NAME to be same as FNR'); - Test.stopTest(); + System.Test.stopTest(); } /*************************** @@ -1503,10 +1503,10 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { KafkaMessage__c message = createKafkaMessage('1122334455666', kafkaPerson); - Test.startTest(); + System.Test.startTest(); insert message; AsyncRequestSchedulable.enqueueAsyncJobs(); - Test.stopTest(); + System.Test.stopTest(); assertProcessed( [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message.Id LIMIT 1] @@ -1593,10 +1593,10 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { KafkaMessage__c message2 = createKafkaMessage('8154968154968', fiddlerPig); KafkaMessage__c message3 = createKafkaMessage('9471759694717', practicalPig); KafkaMessage__c message4 = createKafkaMessage('9691858969185', bigBadWolf); - Test.startTest(); + System.Test.startTest(); insert new List{ message1, message2, message3, message4 }; AsyncRequestSchedulable.enqueueAsyncJobs(); - Test.stopTest(); + System.Test.stopTest(); KafkaMessage__c[] wtf = [SELECT Id, CRM_Key__c, CRM_Status__c, CRM_ErrorMessage__c from KafkaMessage__c]; Person__c[] all = [SELECT Id, INT_ActorId__c, INT_Confidential__c from Person__c]; Integer n = [SELECT COUNT() from Person__c]; @@ -1624,7 +1624,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { CRM_Status__c = KafkaMessageService.STATUS_PENDING ) ); - Test.startTest(); + System.Test.startTest(); KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); handler.processMessages(kafkaMessages); Assert.areEqual( @@ -1632,6 +1632,6 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { kafkaMessages[0].CRM_Status__c, '' + kafkaMessages[0].CRM_ErrorMessage__c ); - Test.stopTest(); + System.Test.stopTest(); } } From 9d202530af11a99b11f9a252cb72a6e534235cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 16 Feb 2024 18:22:22 +0100 Subject: [PATCH 061/159] map INT_DateOfDeath__c Earlier versions used a String for the date and tested it for blankness. This version uses a Date, and therefore the previous String.isNotBlank test has been removed. TODO: check with the PDL team how deaths with an unknown date may be represented in FREG. When PDL is the master, the date should always be known. https://pdldocs-navno.msappproxy.net/ekstern/index.html#_d%C3%B8dsfall_2 --- .../pdl-apexTypes/classes/PDL_Doedsfall.cls | 1 + .../pdl-apexTypes/classes/PDL_Metadata.cls | 1 + .../classes/KafkaPdlPersondokumentHandler.cls | 35 +++++++------------ .../KafkaPdlPersondokumentHandlerTest.cls | 32 +++++------------ 4 files changed, 23 insertions(+), 46 deletions(-) diff --git a/force-app/pdl-apexTypes/classes/PDL_Doedsfall.cls b/force-app/pdl-apexTypes/classes/PDL_Doedsfall.cls index ec9375df..15d1e726 100644 --- a/force-app/pdl-apexTypes/classes/PDL_Doedsfall.cls +++ b/force-app/pdl-apexTypes/classes/PDL_Doedsfall.cls @@ -2,6 +2,7 @@ public with sharing class PDL_Doedsfall { @TestVisible public Date doedsdato{ get;} + @TestVisible public PDL_Metadata metadata{ get;} public PDL_Folkeregistermetadata folkeregistermetadata{ get;} diff --git a/force-app/pdl-apexTypes/classes/PDL_Metadata.cls b/force-app/pdl-apexTypes/classes/PDL_Metadata.cls index 7cf3e727..ee9cae69 100644 --- a/force-app/pdl-apexTypes/classes/PDL_Metadata.cls +++ b/force-app/pdl-apexTypes/classes/PDL_Metadata.cls @@ -1,5 +1,6 @@ public with sharing class PDL_Metadata { public String opplysningsId { get; } + @TestVisible public String master { get; } public PDL_Endring[] endringer { get; } @TestVisible diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 15b8f414..a5401b01 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -350,13 +350,12 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess if (hentPerson.kjoenn.size() > 0) { person.INT_Sex__c = hentPerson.kjoenn[hentPerson.kjoenn.size() - 1].kjoenn.name(); } - /* + // doedsfall - if (kafkaPerson.doedsfall.size() > 0) { - person.INT_DateOfDeath__c = getDoedsfall(kafkaPerson.doedsfall); + if (hentPerson.doedsfall.size() > 0) { + person.INT_DateOfDeath__c = getBestDateOfDeath(hentPerson.doedsfall); person.INT_IsDeceased__c = true; //If we got any records return true even if we don't have a date. } - */ // telefonnummer for (PDL_Telefonnummer tlf : hentPerson.telefonnummer) { @@ -490,28 +489,20 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess /** * Return the date of death - * @param doedsfall list for KafkaPerson2.Doedsfall - * @return Date the first date we find or NULL + * @param deaths list for KafkaPerson2.Doedsfall + * @return Date PDL-date if found, otherwise folkeregister-date, otherwise + * null. */ @TestVisible - private Date getDoedsfall(List doedsfall) { - Map doedsfallMap = new Map(); - - for (KafkaPerson2.Doedsfall element : doedsfall) { - if (String.isNotBlank(element.doedsdato)) { - doedsfallMap.put(element.master.toUpperCase(), Date.valueOf(element.doedsdato)); - } else { - doedsfallMap.put(element.master, null); - } + private Date getBestDateOfDeath(List deaths) { + Map dateAccordingTo = new Map(); + for (PDL_Doedsfall death : deaths) { + dateAccordingTo.put(death.metadata.master.toUpperCase(), Date.valueOf(death.doedsdato)); } - - if (doedsfallMap.containsKey('PDL')) { - return doedsfallMap.get('PDL'); - } else if (doedsfallMap.containsKey('FREG')) { - return doedsfallMap.get('FREG'); + if (dateAccordingTo.containsKey('PDL')) { + return dateAccordingTo.get('PDL'); } - - return null; + return dateAccordingTo.get('FREG'); // null if key does not exist } /** diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index d4f26cbe..8fdd9c3d 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1,32 +1,30 @@ @IsTest private with sharing class KafkaPdlPersondokumentHandlerTest { + /** + * Create data we would otherwise fetch; common codes, and so on. + */ @TestSetup static void makeData() { - // record for setting correct Country from Country ISO code List commonCodes = new List(); - Common_Code__c ccIND = new Common_Code__c(); ccIND.Name = 'India'; ccIND.CRM_Code_Set__c = 'Landkoder'; ccIND.CRM_Code__c = 'IND'; ccIND.CRM_Active__c = true; commonCodes.add(ccIND); - Common_Code__c ccBEL = new Common_Code__c(); ccBEL.Name = 'BELGIA'; ccBEL.CRM_Code_Set__c = 'Landkoder'; ccBEL.CRM_Code__c = 'BEL'; ccBEL.CRM_Active__c = true; commonCodes.add(ccBEL); - Common_Code__c ccNOR = new Common_Code__c(); ccNOR.Name = 'Norge'; ccNOR.CRM_Code_Set__c = 'Landkoder'; ccNOR.CRM_Code__c = 'NOR'; ccNOR.CRM_Active__c = true; commonCodes.add(ccNOR); - insert commonCodes; } @@ -109,6 +107,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { return kp; } + /** + * Pull out all the fields in which we may be interested + */ private static Map getPersonAccountByActorIdent() { Map personByActorIdent = new Map(); for (Person__c person : [ @@ -1463,8 +1464,8 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { kafkaPerson.hentPerson.kjoenn.add(kjoenn); PDL_Doedsfall doedsfall = new PDL_Doedsfall(); doedsfall.doedsdato = Date.valueOf('2019-01-29'); - // TODO - //doedsfall.master = 'FREG'; + doedsfall.metadata = new PDL_Metadata(); + doedsfall.metadata.master = 'FREG'; kafkaPerson.hentPerson.doedsfall.add(doedsfall); PDL_Telefonnummer nummer = new PDL_Telefonnummer(); nummer.landskode = '+46'; @@ -1502,16 +1503,13 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { kafkaPerson.hentPerson.vergemaalEllerFremtidsfullmakt.add(verge); KafkaMessage__c message = createKafkaMessage('1122334455666', kafkaPerson); - System.Test.startTest(); insert message; AsyncRequestSchedulable.enqueueAsyncJobs(); System.Test.stopTest(); - assertProcessed( [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message.Id LIMIT 1] ); - Person__c person = getPersonAccountByActorIdent().get('1122334455666'); Assert.areEqual('1122334455666', person.INT_actorId__c, 'Expected AKTØR ID to be set'); @@ -1519,41 +1517,27 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.isNull(person.INT_npid__c, 'Expected NPID to be null'); Assert.isNull(person.INT_dnr__c, 'Expect DNR to be null'); Assert.areEqual('12345678901', person.Name, 'Expected NAME to be same as FNR'); - Assert.areEqual('2020-02-25', person.INT_DateOfBirth__c); - Assert.areEqual('TREST', person.INT_FirstName__c); Assert.areEqual('T.', person.INT_MiddleName__c); Assert.areEqual('TRESTRESEN', person.INT_LastName__c); - Assert.areEqual('Bosatt', person.INT_LegalStatus__c); - Assert.isNotNull(person.INT_MovedFromCountry__c); Assert.areEqual('Delhi', person.INT_MovedFromPlace__c); - Assert.areEqual('[{"tiltakstype":"TFUS","metadata":null,"kontaktperson":{"personident":"Z000000","enhet":"0000"},"gyldigTilOgMed":"2020-12-20","gyldigFraOgMed":"2020-12-14","beskrivelse":"Telefonisk utestengelse"}]', person.INT_SecurityMeasures__c); - Assert.areEqual('Norge', person.INT_Citizenships__c); - Assert.areEqual('GIFT', person.INT_MaritalStatus__c); Assert.areEqual(Date.newInstance(2001, 6, 20), person.INT_MaritalStatusDate__c); Assert.areEqual('12345678910', person.INT_MaritalRelation__c); - Assert.areEqual('Mann', person.INT_Sex__c); - Assert.areEqual('+47987 65 432', person.INT_Phone1__c); Assert.areEqual('+460765-43 21 07', person.INT_Phone2__c); - Assert.isNotNull(person.INT_MovedToCountry__c); Assert.areEqual('Delhi', person.INT_MovedToPlace__c); - Assert.areEqual('NO', person.INT_SpokenLanguageIntepreter__c); - Assert.areEqual('[{"omraader":["DAG"],"motpartsRolle":"FULLMEKTIG","motpartsPersonident":"12345678910","metadata":null,"gyldigTilOgMed":"2020-02-28","gyldigFraOgMed":"2020-02-14"}]', person.INT_PowerOfAttorney__c); Assert.areEqual('[{"vergeEllerFullmektig":{"omfangetErInnenPersonligOmraade":true,"omfang":"Personlige og/eller økonomiske interesser","navn":null,"motpartsPersonident":"12345678910"},"type":"stadfestetFremtidsfullmakt","metadata":null,"folkeregistermetadata":null,"embete":"Statsforvalter"}]', person.INT_GuardianshipOrFuturePowerOfAttorney__c); - Assert.areEqual('UGRADERT', person.INT_Confidential__c); - Assert.areEqual(Date.newInstance(2019, 1, 29), person.INT_DateOfDeath__c); Assert.areEqual(true, person.INT_IsDeceased__c); } From 58156909ca792f3af08697ebb24b8dd9f5b978e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 19 Feb 2024 15:58:21 +0100 Subject: [PATCH 062/159] explain why we empty the fields --- .../pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index a5401b01..e9f32f44 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -255,7 +255,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess return person; } - emptyPersonFieldValues(person); // why is this necessary? + emptyPersonFieldValues(person); String decodedValue = KafkaMessageUtils.base64ULSafeDecode(message.CRM_Value__c).toString(); // Fail loudly when deserialization goes wrong. @@ -767,8 +767,12 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * Sets empty value for all Person__c fields + * Sets empty value for all Person__c fields. Ensures that e.g. + * INT_DateOfDeath__c is removed when it has previously been erroneously set + * — and then corrected by creating a person document that does not contain + * a date of death. * @param person record to modify + * TODO: ensure we haven't missed anything. */ @TestVisible private static void emptyPersonFieldValues(Person__c person) { From ac7a2cb903910d61939f0a292c9b220b8529512e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 23 Feb 2024 16:20:31 +0100 Subject: [PATCH 063/159] minor --- .../pdl-handler/classes/KafkaPdlGtHandlerTest.cls | 4 ++-- .../classes/KafkaPdlPersondokumentHandlerTest.cls | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index 066315a3..e399b131 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -25,11 +25,11 @@ private with sharing class KafkaPdlGtHandlerTest { CRM_Status__c = KafkaMessageService.STATUS_PENDING ) ); - Test.startTest(); KafkaPdlGtHandler handler = new KafkaPdlGtHandler(); + Test.startTest(); handler.processMessages(kafkaMessages); + Test.stopTest(); List pl = [SELECT Id from Person__c where INT_ActorId__c = '1017419408436']; Assert.areEqual(1, pl.size(), 'Expected one person inserted.'); - Test.stopTest(); } } diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 8fdd9c3d..4f51bbd3 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -496,12 +496,12 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { CRM_Status__c = KafkaMessageService.STATUS_PENDING ) ); - System.Test.startTest(); KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); + System.Test.startTest(); handler.processMessages(kafkaMessages); + System.Test.stopTest(); List pl = [SELECT Id from Person__c where INT_ActorId__c = '2594819806563']; Assert.areEqual(1, pl.size(), 'Expected one person inserted.'); - System.Test.stopTest(); } @isTest @@ -515,13 +515,13 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { CRM_Status__c = KafkaMessageService.STATUS_PENDING ) ); - System.Test.startTest(); Integer numPersonsBefore = [select id from person__c].size(); KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); + System.Test.startTest(); handler.processMessages(kafkaMessages); + System.Test.stopTest(); Assert.areEqual(numPersonsBefore, [select id from person__c].size(), 'Expected none inserted.'); - System.Test.stopTest(); } /******************************************* @@ -559,14 +559,14 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { kPerson.hentIdenter.identer[i].historisk = true; kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; Person__c person = new Person__c(); - System.Test.startTest(); + System.Test.startTest(); // eh KafkaPdlPersondokumentHandler.setName(person, kPerson.hentIdenter); Assert.areEqual('12345678901', person.Name, 'Expected non historisk FOLKEREGISTERIDENT'); person = new Person__c(); kPerson.hentIdenter.identer[fregIndex].historisk = true; KafkaPdlPersondokumentHandler.setName(person, kPerson.hentIdenter); - Assert.areEqual('12345678911', person.Name, 'Expected non historisk NPID'); System.Test.stopTest(); + Assert.areEqual('12345678911', person.Name, 'Expected non historisk NPID'); } @IsTest @@ -1611,11 +1611,11 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { System.Test.startTest(); KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); handler.processMessages(kafkaMessages); + System.Test.stopTest(); Assert.areEqual( KafkaMessageService.STATUS_ERROR, kafkaMessages[0].CRM_Status__c, '' + kafkaMessages[0].CRM_ErrorMessage__c ); - System.Test.stopTest(); } } From edd68b52c032b941878594ff115d579fd4dd250c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 23 Feb 2024 16:20:43 +0100 Subject: [PATCH 064/159] shorten, comment tests a bit --- .../classes/KafkaPdlGtHandlerTest.cls | 15 +- .../KafkaPdlPersondokumentHandlerTest.cls | 349 +----------------- 2 files changed, 15 insertions(+), 349 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index e399b131..f10d1d9c 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -8,20 +8,7 @@ private with sharing class KafkaPdlGtHandlerTest { new KafkaMessage__c( CRM_Topic__c = 'pdl.geografisktilknytning-v1', CRM_Key__c = '1017419408436', - //{ - // "identer": [ - // "1017419408436", - // "74194084361" - // ], - // "geografiskTilknytning": { - // "gtType": "KOMMUNE", - // "gtKommune": "1337", - // "gtBydel": null, - // "gtLand": null, - // "regel": "2" - // } - //} - CRM_Value__c = 'eyJpZGVudGVyIjpbIjEwMTc0MTk0MDg0MzYiLCI3NDE5NDA4NDM2MSJdLCJnZW9ncmFmaXNrVGlsa255dG5pbmciOnsiZ3RUeXBlIjoiS09NTVVORSIsImd0S29tbXVuZSI6IjEzMzciLCJndEJ5ZGVsIjpudWxsLCJndExhbmQiOm51bGwsInJlZ2VsIjoiMiJ9fQo=', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["1017419408436","74194084361"],"geografiskTilknytning":{"gtType":"KOMMUNE","gtKommune":"1337","gtBydel":null,"gtLand":null,"regel":"2"}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING ) ); diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 4f51bbd3..e9b8388a 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -2,7 +2,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { /** - * Create data we would otherwise fetch; common codes, and so on. + * Creates data we would otherwise fetch; common codes, and so on. */ @TestSetup static void makeData() { @@ -29,8 +29,8 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { } /** - * Helper that lets us avoid initialising every part of a KafkaPerson3, - * PDL_IdentInformasjon, or PDL_HentPerson every time + * Initializes KafkaPerson3 with PDL_IdentInformasjon and PDL_HentPerson, + * similar to what we expect to receive as a minimum from PDL. */ private static KafkaPerson3 createBaseKafkaPerson(String actorId) { KafkaPerson3 kp = new KafkaPerson3(); @@ -65,17 +65,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { kp.hentPerson.utenlandskIdentifikasjonsnummer = new List(); kp.hentPerson.utflyttingFraNorge = new List(); kp.hentPerson.vergemaalEllerFremtidsfullmakt = new List(); - // no longer necessary? - //kp.hentPerson.bostedsadresse.matrikkeladresse = new List(); - //kp.hentPerson.bostedsadresse.ukjentBosted = new List(); - //kp.hentPerson.bostedsadresse.utenlandskAdresse = new List(); - //kp.hentPerson.bostedsadresse.vegadresse = new List(); + // TODO: decide exactly what to do with these two //kp.hentPerson.bydelsnummerFraGt = ''; //kp.hentPerson.kommunenummerFraGt = ''; - //kp.hentPerson.oppholdsadresse.matrikkeladresse = new List(); - //kp.hentPerson.oppholdsadresse.ukjentBosted = new List(); - //kp.hentPerson.oppholdsadresse.utenlandskAdresse = new List(); - //kp.hentPerson.oppholdsadresse.vegadresse = new List(); // Default values // Ident kp.hentIdenter.identer.add(new PDL_IdentInformasjon()); @@ -83,10 +75,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { kp.hentIdenter.identer[0].historisk = false; kp.hentIdenter.identer[0].ident = actorId; // Person status - // isn't there a better way than initializing all of these manually? kp.hentPerson.folkeregisterpersonstatus.add(new PDL_Folkeregisterpersonstatus()); kp.hentPerson.folkeregisterpersonstatus[0].status = 'bosatt'; - // Navn + // Name kp.hentPerson.navn.add(new PDL_Navn()); kp.hentPerson.navn[0].etternavn = 'TRESTRESEN'; kp.hentPerson.adressebeskyttelse.add(new PDL_Adressebeskyttelse()); @@ -95,7 +86,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { } /** - * As createBaseKafkaPerson(String), but also initialize with a folkeregisterident + * Calls createBaseKafkaPerson(String), and adds a folkeregisterident */ private static KafkaPerson3 createBaseKafkaPerson(String actorId, String fregId) { KafkaPerson3 kp = createBaseKafkaPerson(actorId); @@ -108,7 +99,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { } /** - * Pull out all the fields in which we may be interested + * Pulls out all the fields in which we may be interested */ private static Map getPersonAccountByActorIdent() { Map personByActorIdent = new Map(); @@ -169,6 +160,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { return personByActorIdent; } + /** + * Test for a typical Dolly person + */ @isTest static void testCreatePersonFromPersonDokument() { List kafkaMessages = new List(); @@ -176,323 +170,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { new KafkaMessage__c( CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', CRM_Key__c = '2594819806563', - //{ - // "hentPerson": { - // "adressebeskyttelse": [], - // "bostedsadresse": [ - // { - // "angittFlyttedato": "1972-07-01", - // "gyldigFraOgMed": "1972-07-01T00:00:00", - // "gyldigTilOgMed": null, - // "coAdressenavn": null, - // "vegadresse": { - // "matrikkelId": 138391329, - // "husnummer": "11", - // "husbokstav": null, - // "bruksenhetsnummer": null, - // "adressenavn": "Marihandstien", - // "kommunenummer": "1806", - // "tilleggsnavn": null, - // "postnummer": "8515", - // "bydelsnummer": null, - // "koordinater": { - // "x": 599891.371546, - // "y": 7592866.900335, - // "z": null - // } - // }, - // "matrikkeladresse": null, - // "ukjentBosted": null, - // "utenlandskAdresse": null, - // "folkeregistermetadata": { - // "ajourholdstidspunkt": "2022-01-14T15:41:37.045", - // "gyldighetstidspunkt": "1972-07-01T00:00:00", - // "opphoerstidspunkt": null, - // "kilde": "Dolly", - // "aarsak": null, - // "sekvens": null - // }, - // "metadata": { - // "opplysningsId": "e52735a2-be2f-4b2a-b578-dec2f032e8dd", - // "master": "FREG", - // "endringer": [ - // { - // "type": "OPPRETT", - // "registrert": "2022-01-14T15:41:37.045", - // "registrertAv": "Folkeregisteret", - // "systemkilde": "FREG", - // "kilde": "Dolly" - // } - // ], - // "historisk": false - // } - // } - // ], - // "doedsfall": [], - // "foedsel": [ - // { - // "foedselsaar": 1972, - // "foedselsdato": "1972-07-01", - // "foedeland": "BEL", - // "foedested": "Fødested i/på BELGIA", - // "foedekommune": null, - // "metadata": { - // "opplysningsId": "fadd61cf-0da2-4df1-9492-a5fb1532f50f", - // "master": "FREG", - // "endringer": [ - // { - // "type": "OPPRETT", - // "registrert": "2022-01-14T15:41:35.412", - // "registrertAv": "Folkeregisteret", - // "systemkilde": "FREG", - // "kilde": "Dolly" - // } - // ], - // "historisk": false - // }, - // "folkeregistermetadata": { - // "ajourholdstidspunkt": "2022-01-14T15:41:35.412", - // "gyldighetstidspunkt": "2022-01-14T15:41:35.412", - // "opphoerstidspunkt": null, - // "kilde": "Dolly", - // "aarsak": null, - // "sekvens": null - // } - // } - // ], - // "folkeregisteridentifikator": [ - // { - // "identifikasjonsnummer": "01077211027", - // "type": "FNR", - // "status": "I_BRUK", - // "folkeregistermetadata": { - // "ajourholdstidspunkt": "2022-01-14T15:41:34.945", - // "gyldighetstidspunkt": "2022-01-14T15:41:34.945", - // "opphoerstidspunkt": null, - // "kilde": "srvdolly", - // "aarsak": null, - // "sekvens": null - // }, - // "metadata": { - // "opplysningsId": "4ed45e87-e02b-4aa0-8601-689bbd58f20f", - // "master": "FREG", - // "endringer": [ - // { - // "type": "OPPRETT", - // "registrert": "2022-01-14T15:41:35.058", - // "registrertAv": "Folkeregisteret", - // "systemkilde": "FREG", - // "kilde": "srvdolly" - // } - // ], - // "historisk": false - // } - // } - // ], - // "folkeregisterpersonstatus": [ - // { - // "status": "bosatt", - // "forenkletStatus": "bosattEtterFolkeregisterloven", - // "folkeregistermetadata": { - // "ajourholdstidspunkt": "2022-01-14T15:41:37.899", - // "gyldighetstidspunkt": "2022-01-14T15:41:37.899", - // "opphoerstidspunkt": null, - // "kilde": "Dolly", - // "aarsak": null, - // "sekvens": null - // }, - // "metadata": { - // "opplysningsId": "37065f2d-5f9e-4046-a6d3-9f6856961cd6", - // "master": "FREG", - // "endringer": [ - // { - // "type": "OPPRETT", - // "registrert": "2022-01-14T15:41:37.899", - // "registrertAv": "Folkeregisteret", - // "systemkilde": "FREG", - // "kilde": "Dolly" - // } - // ], - // "historisk": false - // } - // } - // ], - // "forelderBarnRelasjon": [], - // "fullmakt": [], - // "kjoenn": [ - // { - // "kjoenn": "KVINNE", - // "folkeregistermetadata": { - // "ajourholdstidspunkt": "2022-01-14T15:41:36.62", - // "gyldighetstidspunkt": "2022-01-14T15:41:36.62", - // "opphoerstidspunkt": null, - // "kilde": "Dolly", - // "aarsak": null, - // "sekvens": null - // }, - // "metadata": { - // "opplysningsId": "0847b543-0847-4494-9fca-857a1ca51a73", - // "master": "FREG", - // "endringer": [ - // { - // "type": "OPPRETT", - // "registrert": "2022-01-14T15:41:36.62", - // "registrertAv": "Folkeregisteret", - // "systemkilde": "FREG", - // "kilde": "Dolly" - // } - // ], - // "historisk": false - // } - // } - // ], - // "navn": [ - // { - // "fornavn": "ARTIG", - // "mellomnavn": null, - // "etternavn": "SNERK", - // "forkortetNavn": "SNERK ARTIG", - // "originaltNavn": null, - // "gyldigFraOgMed": "2022-01-14", - // "folkeregistermetadata": { - // "ajourholdstidspunkt": "2022-01-14T15:41:36.237", - // "gyldighetstidspunkt": "2022-01-14T15:41:36.237", - // "opphoerstidspunkt": null, - // "kilde": "Dolly", - // "aarsak": null, - // "sekvens": null - // }, - // "metadata": { - // "opplysningsId": "44fbf7a6-6885-48ad-a303-e9d90fa4567f", - // "master": "FREG", - // "endringer": [ - // { - // "type": "OPPRETT", - // "registrert": "2022-01-14T15:41:36.237", - // "registrertAv": "Folkeregisteret", - // "systemkilde": "FREG", - // "kilde": "Dolly" - // } - // ], - // "historisk": false - // } - // } - // ], - // "oppholdsadresse": [], - // "sikkerhetstiltak": [], - // "sivilstand": [ - // { - // "type": "UGIFT", - // "gyldigFraOgMed": null, - // "relatertVedSivilstand": null, - // "bekreftelsesdato": null, - // "folkeregistermetadata": { - // "ajourholdstidspunkt": "2022-01-14T15:41:38.684", - // "gyldighetstidspunkt": "2022-01-14T15:41:38.684", - // "opphoerstidspunkt": null, - // "kilde": "Dolly", - // "aarsak": null, - // "sekvens": null - // }, - // "metadata": { - // "opplysningsId": "2d7f6623-3ba4-44d3-8e04-efced8cd77e3", - // "master": "FREG", - // "endringer": [ - // { - // "type": "OPPRETT", - // "registrert": "2022-01-14T15:41:38.684", - // "registrertAv": "Folkeregisteret", - // "systemkilde": "FREG", - // "kilde": "Dolly" - // } - // ], - // "historisk": false - // } - // } - // ], - // "statsborgerskap": [ - // { - // "land": "NOR", - // "bekreftelsesdato": null, - // "gyldigFraOgMed": "1972-07-01", - // "gyldigTilOgMed": null, - // "folkeregistermetadata": { - // "ajourholdstidspunkt": "2022-01-14T15:41:38.327", - // "gyldighetstidspunkt": "1972-07-01T00:00:00", - // "opphoerstidspunkt": null, - // "kilde": "Dolly", - // "aarsak": null, - // "sekvens": null - // }, - // "metadata": { - // "opplysningsId": "672b293a-b18e-4cd1-9a16-d4a03eb8581d", - // "master": "FREG", - // "endringer": [ - // { - // "type": "OPPRETT", - // "registrert": "2022-01-14T15:41:38.326", - // "registrertAv": "Folkeregisteret", - // "systemkilde": "FREG", - // "kilde": "Dolly" - // } - // ], - // "historisk": false - // } - // } - // ], - // "tilrettelagtKommunikasjon": [], - // "telefonnummer": [], - // "innflyttingTilNorge": [ - // { - // "fraflyttingsland": "BEL", - // "fraflyttingsstedIUtlandet": null, - // "folkeregistermetadata": { - // "ajourholdstidspunkt": "2022-01-14T15:41:37.532", - // "gyldighetstidspunkt": "1972-07-01T00:00:00", - // "opphoerstidspunkt": null, - // "kilde": "Dolly", - // "aarsak": null, - // "sekvens": null - // }, - // "metadata": { - // "opplysningsId": "5345af76-ac03-4461-9d5c-f17c42ea8a32", - // "master": "FREG", - // "endringer": [ - // { - // "type": "OPPRETT", - // "registrert": "2022-01-14T15:41:37.532", - // "registrertAv": "Folkeregisteret", - // "systemkilde": "FREG", - // "kilde": "Dolly" - // } - // ], - // "historisk": false - // } - // } - // ], - // "utflyttingFraNorge": [], - // "vergemaalEllerFremtidsfullmakt": [] - // }, - // "hentIdenter": { - // "identer": [ - // { - // "ident": "01077211027", - // "historisk": false, - // "gruppe": "FOLKEREGISTERIDENT", - // "metadata": null, - // "folkeregistermetadata": null - // }, - // { - // "ident": "2594819806563", - // "historisk": false, - // "gruppe": "AKTORID", - // "metadata": null, - // "folkeregistermetadata": null - // } - // ] - // } - //} - CRM_Value__c = 'eyJoZW50UGVyc29uIjp7ImFkcmVzc2ViZXNreXR0ZWxzZSI6W10sImJvc3RlZHNhZHJlc3NlIjpbeyJhbmdpdHRGbHl0dGVkYXRvIjoiMTk3Mi0wNy0wMSIsImd5bGRpZ0ZyYU9nTWVkIjoiMTk3Mi0wNy0wMVQwMDowMDowMCIsImd5bGRpZ1RpbE9nTWVkIjpudWxsLCJjb0FkcmVzc2VuYXZuIjpudWxsLCJ2ZWdhZHJlc3NlIjp7Im1hdHJpa2tlbElkIjoxMzgzOTEzMjksImh1c251bW1lciI6IjExIiwiaHVzYm9rc3RhdiI6bnVsbCwiYnJ1a3NlbmhldHNudW1tZXIiOm51bGwsImFkcmVzc2VuYXZuIjoiTWFyaWhhbmRzdGllbiIsImtvbW11bmVudW1tZXIiOiIxODA2IiwidGlsbGVnZ3NuYXZuIjpudWxsLCJwb3N0bnVtbWVyIjoiODUxNSIsImJ5ZGVsc251bW1lciI6bnVsbCwia29vcmRpbmF0ZXIiOnsieCI6NTk5ODkxLjM3MTU0NiwieSI6NzU5Mjg2Ni45MDAzMzUsInoiOm51bGx9fSwibWF0cmlra2VsYWRyZXNzZSI6bnVsbCwidWtqZW50Qm9zdGVkIjpudWxsLCJ1dGVubGFuZHNrQWRyZXNzZSI6bnVsbCwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjp7ImFqb3VyaG9sZHN0aWRzcHVua3QiOiIyMDIyLTAxLTE0VDE1OjQxOjM3LjA0NSIsImd5bGRpZ2hldHN0aWRzcHVua3QiOiIxOTcyLTA3LTAxVDAwOjAwOjAwIiwib3BwaG9lcnN0aWRzcHVua3QiOm51bGwsImtpbGRlIjoiRG9sbHkiLCJhYXJzYWsiOm51bGwsInNla3ZlbnMiOm51bGx9LCJtZXRhZGF0YSI6eyJvcHBseXNuaW5nc0lkIjoiZTUyNzM1YTItYmUyZi00YjJhLWI1NzgtZGVjMmYwMzJlOGRkIiwibWFzdGVyIjoiRlJFRyIsImVuZHJpbmdlciI6W3sidHlwZSI6Ik9QUFJFVFQiLCJyZWdpc3RyZXJ0IjoiMjAyMi0wMS0xNFQxNTo0MTozNy4wNDUiLCJyZWdpc3RyZXJ0QXYiOiJGb2xrZXJlZ2lzdGVyZXQiLCJzeXN0ZW1raWxkZSI6IkZSRUciLCJraWxkZSI6IkRvbGx5In1dLCJoaXN0b3Jpc2siOmZhbHNlfX1dLCJkb2Vkc2ZhbGwiOltdLCJmb2Vkc2VsIjpbeyJmb2Vkc2Vsc2FhciI6MTk3MiwiZm9lZHNlbHNkYXRvIjoiMTk3Mi0wNy0wMSIsImZvZWRlbGFuZCI6IkJFTCIsImZvZWRlc3RlZCI6IkbDuGRlc3RlZCBpL3DDpSBCRUxHSUEiLCJmb2VkZWtvbW11bmUiOm51bGwsIm1ldGFkYXRhIjp7Im9wcGx5c25pbmdzSWQiOiJmYWRkNjFjZi0wZGEyLTRkZjEtOTQ5Mi1hNWZiMTUzMmY1MGYiLCJtYXN0ZXIiOiJGUkVHIiwiZW5kcmluZ2VyIjpbeyJ0eXBlIjoiT1BQUkVUVCIsInJlZ2lzdHJlcnQiOiIyMDIyLTAxLTE0VDE1OjQxOjM1LjQxMiIsInJlZ2lzdHJlcnRBdiI6IkZvbGtlcmVnaXN0ZXJldCIsInN5c3RlbWtpbGRlIjoiRlJFRyIsImtpbGRlIjoiRG9sbHkifV0sImhpc3RvcmlzayI6ZmFsc2V9LCJmb2xrZXJlZ2lzdGVybWV0YWRhdGEiOnsiYWpvdXJob2xkc3RpZHNwdW5rdCI6IjIwMjItMDEtMTRUMTU6NDE6MzUuNDEyIiwiZ3lsZGlnaGV0c3RpZHNwdW5rdCI6IjIwMjItMDEtMTRUMTU6NDE6MzUuNDEyIiwib3BwaG9lcnN0aWRzcHVua3QiOm51bGwsImtpbGRlIjoiRG9sbHkiLCJhYXJzYWsiOm51bGwsInNla3ZlbnMiOm51bGx9fV0sImZvbGtlcmVnaXN0ZXJpZGVudGlmaWthdG9yIjpbeyJpZGVudGlmaWthc2pvbnNudW1tZXIiOiIwMTA3NzIxMTAyNyIsInR5cGUiOiJGTlIiLCJzdGF0dXMiOiJJX0JSVUsiLCJmb2xrZXJlZ2lzdGVybWV0YWRhdGEiOnsiYWpvdXJob2xkc3RpZHNwdW5rdCI6IjIwMjItMDEtMTRUMTU6NDE6MzQuOTQ1IiwiZ3lsZGlnaGV0c3RpZHNwdW5rdCI6IjIwMjItMDEtMTRUMTU6NDE6MzQuOTQ1Iiwib3BwaG9lcnN0aWRzcHVua3QiOm51bGwsImtpbGRlIjoic3J2ZG9sbHkiLCJhYXJzYWsiOm51bGwsInNla3ZlbnMiOm51bGx9LCJtZXRhZGF0YSI6eyJvcHBseXNuaW5nc0lkIjoiNGVkNDVlODctZTAyYi00YWEwLTg2MDEtNjg5YmJkNThmMjBmIiwibWFzdGVyIjoiRlJFRyIsImVuZHJpbmdlciI6W3sidHlwZSI6Ik9QUFJFVFQiLCJyZWdpc3RyZXJ0IjoiMjAyMi0wMS0xNFQxNTo0MTozNS4wNTgiLCJyZWdpc3RyZXJ0QXYiOiJGb2xrZXJlZ2lzdGVyZXQiLCJzeXN0ZW1raWxkZSI6IkZSRUciLCJraWxkZSI6InNydmRvbGx5In1dLCJoaXN0b3Jpc2siOmZhbHNlfX1dLCJmb2xrZXJlZ2lzdGVycGVyc29uc3RhdHVzIjpbeyJzdGF0dXMiOiJib3NhdHQiLCJmb3JlbmtsZXRTdGF0dXMiOiJib3NhdHRFdHRlckZvbGtlcmVnaXN0ZXJsb3ZlbiIsImZvbGtlcmVnaXN0ZXJtZXRhZGF0YSI6eyJham91cmhvbGRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTozNy44OTkiLCJneWxkaWdoZXRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTozNy44OTkiLCJvcHBob2Vyc3RpZHNwdW5rdCI6bnVsbCwia2lsZGUiOiJEb2xseSIsImFhcnNhayI6bnVsbCwic2VrdmVucyI6bnVsbH0sIm1ldGFkYXRhIjp7Im9wcGx5c25pbmdzSWQiOiIzNzA2NWYyZC01ZjllLTQwNDYtYTZkMy05ZjY4NTY5NjFjZDYiLCJtYXN0ZXIiOiJGUkVHIiwiZW5kcmluZ2VyIjpbeyJ0eXBlIjoiT1BQUkVUVCIsInJlZ2lzdHJlcnQiOiIyMDIyLTAxLTE0VDE1OjQxOjM3Ljg5OSIsInJlZ2lzdHJlcnRBdiI6IkZvbGtlcmVnaXN0ZXJldCIsInN5c3RlbWtpbGRlIjoiRlJFRyIsImtpbGRlIjoiRG9sbHkifV0sImhpc3RvcmlzayI6ZmFsc2V9fV0sImZvcmVsZGVyQmFyblJlbGFzam9uIjpbXSwiZnVsbG1ha3QiOltdLCJram9lbm4iOlt7Imtqb2VubiI6IktWSU5ORSIsImZvbGtlcmVnaXN0ZXJtZXRhZGF0YSI6eyJham91cmhvbGRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTozNi42MiIsImd5bGRpZ2hldHN0aWRzcHVua3QiOiIyMDIyLTAxLTE0VDE1OjQxOjM2LjYyIiwib3BwaG9lcnN0aWRzcHVua3QiOm51bGwsImtpbGRlIjoiRG9sbHkiLCJhYXJzYWsiOm51bGwsInNla3ZlbnMiOm51bGx9LCJtZXRhZGF0YSI6eyJvcHBseXNuaW5nc0lkIjoiMDg0N2I1NDMtMDg0Ny00NDk0LTlmY2EtODU3YTFjYTUxYTczIiwibWFzdGVyIjoiRlJFRyIsImVuZHJpbmdlciI6W3sidHlwZSI6Ik9QUFJFVFQiLCJyZWdpc3RyZXJ0IjoiMjAyMi0wMS0xNFQxNTo0MTozNi42MiIsInJlZ2lzdHJlcnRBdiI6IkZvbGtlcmVnaXN0ZXJldCIsInN5c3RlbWtpbGRlIjoiRlJFRyIsImtpbGRlIjoiRG9sbHkifV0sImhpc3RvcmlzayI6ZmFsc2V9fV0sIm5hdm4iOlt7ImZvcm5hdm4iOiJBUlRJRyIsIm1lbGxvbW5hdm4iOm51bGwsImV0dGVybmF2biI6IlNORVJLIiwiZm9ya29ydGV0TmF2biI6IlNORVJLIEFSVElHIiwib3JpZ2luYWx0TmF2biI6bnVsbCwiZ3lsZGlnRnJhT2dNZWQiOiIyMDIyLTAxLTE0IiwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjp7ImFqb3VyaG9sZHN0aWRzcHVua3QiOiIyMDIyLTAxLTE0VDE1OjQxOjM2LjIzNyIsImd5bGRpZ2hldHN0aWRzcHVua3QiOiIyMDIyLTAxLTE0VDE1OjQxOjM2LjIzNyIsIm9wcGhvZXJzdGlkc3B1bmt0IjpudWxsLCJraWxkZSI6IkRvbGx5IiwiYWFyc2FrIjpudWxsLCJzZWt2ZW5zIjpudWxsfSwibWV0YWRhdGEiOnsib3BwbHlzbmluZ3NJZCI6IjQ0ZmJmN2E2LTY4ODUtNDhhZC1hMzAzLWU5ZDkwZmE0NTY3ZiIsIm1hc3RlciI6IkZSRUciLCJlbmRyaW5nZXIiOlt7InR5cGUiOiJPUFBSRVRUIiwicmVnaXN0cmVydCI6IjIwMjItMDEtMTRUMTU6NDE6MzYuMjM3IiwicmVnaXN0cmVydEF2IjoiRm9sa2VyZWdpc3RlcmV0Iiwic3lzdGVta2lsZGUiOiJGUkVHIiwia2lsZGUiOiJEb2xseSJ9XSwiaGlzdG9yaXNrIjpmYWxzZX19XSwib3BwaG9sZHNhZHJlc3NlIjpbXSwic2lra2VyaGV0c3RpbHRhayI6W10sInNpdmlsc3RhbmQiOlt7InR5cGUiOiJVR0lGVCIsImd5bGRpZ0ZyYU9nTWVkIjpudWxsLCJyZWxhdGVydFZlZFNpdmlsc3RhbmQiOm51bGwsImJla3JlZnRlbHNlc2RhdG8iOm51bGwsImZvbGtlcmVnaXN0ZXJtZXRhZGF0YSI6eyJham91cmhvbGRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTozOC42ODQiLCJneWxkaWdoZXRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTozOC42ODQiLCJvcHBob2Vyc3RpZHNwdW5rdCI6bnVsbCwia2lsZGUiOiJEb2xseSIsImFhcnNhayI6bnVsbCwic2VrdmVucyI6bnVsbH0sIm1ldGFkYXRhIjp7Im9wcGx5c25pbmdzSWQiOiIyZDdmNjYyMy0zYmE0LTQ0ZDMtOGUwNC1lZmNlZDhjZDc3ZTMiLCJtYXN0ZXIiOiJGUkVHIiwiZW5kcmluZ2VyIjpbeyJ0eXBlIjoiT1BQUkVUVCIsInJlZ2lzdHJlcnQiOiIyMDIyLTAxLTE0VDE1OjQxOjM4LjY4NCIsInJlZ2lzdHJlcnRBdiI6IkZvbGtlcmVnaXN0ZXJldCIsInN5c3RlbWtpbGRlIjoiRlJFRyIsImtpbGRlIjoiRG9sbHkifV0sImhpc3RvcmlzayI6ZmFsc2V9fV0sInN0YXRzYm9yZ2Vyc2thcCI6W3sibGFuZCI6Ik5PUiIsImJla3JlZnRlbHNlc2RhdG8iOm51bGwsImd5bGRpZ0ZyYU9nTWVkIjoiMTk3Mi0wNy0wMSIsImd5bGRpZ1RpbE9nTWVkIjpudWxsLCJmb2xrZXJlZ2lzdGVybWV0YWRhdGEiOnsiYWpvdXJob2xkc3RpZHNwdW5rdCI6IjIwMjItMDEtMTRUMTU6NDE6MzguMzI3IiwiZ3lsZGlnaGV0c3RpZHNwdW5rdCI6IjE5NzItMDctMDFUMDA6MDA6MDAiLCJvcHBob2Vyc3RpZHNwdW5rdCI6bnVsbCwia2lsZGUiOiJEb2xseSIsImFhcnNhayI6bnVsbCwic2VrdmVucyI6bnVsbH0sIm1ldGFkYXRhIjp7Im9wcGx5c25pbmdzSWQiOiI2NzJiMjkzYS1iMThlLTRjZDEtOWExNi1kNGEwM2ViODU4MWQiLCJtYXN0ZXIiOiJGUkVHIiwiZW5kcmluZ2VyIjpbeyJ0eXBlIjoiT1BQUkVUVCIsInJlZ2lzdHJlcnQiOiIyMDIyLTAxLTE0VDE1OjQxOjM4LjMyNiIsInJlZ2lzdHJlcnRBdiI6IkZvbGtlcmVnaXN0ZXJldCIsInN5c3RlbWtpbGRlIjoiRlJFRyIsImtpbGRlIjoiRG9sbHkifV0sImhpc3RvcmlzayI6ZmFsc2V9fV0sInRpbHJldHRlbGFndEtvbW11bmlrYXNqb24iOltdLCJ0ZWxlZm9ubnVtbWVyIjpbXSwiaW5uZmx5dHRpbmdUaWxOb3JnZSI6W3siZnJhZmx5dHRpbmdzbGFuZCI6IkJFTCIsImZyYWZseXR0aW5nc3N0ZWRJVXRsYW5kZXQiOm51bGwsImZvbGtlcmVnaXN0ZXJtZXRhZGF0YSI6eyJham91cmhvbGRzdGlkc3B1bmt0IjoiMjAyMi0wMS0xNFQxNTo0MTozNy41MzIiLCJneWxkaWdoZXRzdGlkc3B1bmt0IjoiMTk3Mi0wNy0wMVQwMDowMDowMCIsIm9wcGhvZXJzdGlkc3B1bmt0IjpudWxsLCJraWxkZSI6IkRvbGx5IiwiYWFyc2FrIjpudWxsLCJzZWt2ZW5zIjpudWxsfSwibWV0YWRhdGEiOnsib3BwbHlzbmluZ3NJZCI6IjUzNDVhZjc2LWFjMDMtNDQ2MS05ZDVjLWYxN2M0MmVhOGEzMiIsIm1hc3RlciI6IkZSRUciLCJlbmRyaW5nZXIiOlt7InR5cGUiOiJPUFBSRVRUIiwicmVnaXN0cmVydCI6IjIwMjItMDEtMTRUMTU6NDE6MzcuNTMyIiwicmVnaXN0cmVydEF2IjoiRm9sa2VyZWdpc3RlcmV0Iiwic3lzdGVta2lsZGUiOiJGUkVHIiwia2lsZGUiOiJEb2xseSJ9XSwiaGlzdG9yaXNrIjpmYWxzZX19XSwidXRmbHl0dGluZ0ZyYU5vcmdlIjpbXSwidmVyZ2VtYWFsRWxsZXJGcmVtdGlkc2Z1bGxtYWt0IjpbXX0sImhlbnRJZGVudGVyIjp7ImlkZW50ZXIiOlt7ImlkZW50IjoiMDEwNzcyMTEwMjciLCJoaXN0b3Jpc2siOmZhbHNlLCJncnVwcGUiOiJGT0xLRVJFR0lTVEVSSURFTlQiLCJtZXRhZGF0YSI6bnVsbCwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjpudWxsfSx7ImlkZW50IjoiMjU5NDgxOTgwNjU2MyIsImhpc3RvcmlzayI6ZmFsc2UsImdydXBwZSI6IkFLVE9SSUQiLCJtZXRhZGF0YSI6bnVsbCwiZm9sa2VyZWdpc3Rlcm1ldGFkYXRhIjpudWxsfV19fQo=', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"hentPerson":{"adressebeskyttelse":[],"bostedsadresse":[{"angittFlyttedato":"1972-07-01","gyldigFraOgMed":"1972-07-01T00:00:00","gyldigTilOgMed":null,"coAdressenavn":null,"vegadresse":{"matrikkelId":138391329,"husnummer":"11","husbokstav":null,"bruksenhetsnummer":null,"adressenavn":"Marihandstien","kommunenummer":"1806","tilleggsnavn":null,"postnummer":"8515","bydelsnummer":null,"koordinater":{"x":599891.371546,"y":7592866.900335,"z":null}},"matrikkeladresse":null,"ukjentBosted":null,"utenlandskAdresse":null,"folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:37.045","gyldighetstidspunkt":"1972-07-01T00:00:00","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"e52735a2-be2f-4b2a-b578-dec2f032e8dd","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:37.045","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"doedsfall":[],"foedsel":[{"foedselsaar":1972,"foedselsdato":"1972-07-01","foedeland":"BEL","foedested":"Fødested i/på BELGIA","foedekommune":null,"metadata":{"opplysningsId":"fadd61cf-0da2-4df1-9492-a5fb1532f50f","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:35.412","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false},"folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:35.412","gyldighetstidspunkt":"2022-01-14T15:41:35.412","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null}}],"folkeregisteridentifikator":[{"identifikasjonsnummer":"01077211027","type":"FNR","status":"I_BRUK","folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:34.945","gyldighetstidspunkt":"2022-01-14T15:41:34.945","opphoerstidspunkt":null,"kilde":"srvdolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"4ed45e87-e02b-4aa0-8601-689bbd58f20f","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:35.058","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"srvdolly"}],"historisk":false}}],"folkeregisterpersonstatus":[{"status":"bosatt","forenkletStatus":"bosattEtterFolkeregisterloven","folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:37.899","gyldighetstidspunkt":"2022-01-14T15:41:37.899","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"37065f2d-5f9e-4046-a6d3-9f6856961cd6","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:37.899","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"forelderBarnRelasjon":[],"fullmakt":[],"kjoenn":[{"kjoenn":"KVINNE","folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:36.62","gyldighetstidspunkt":"2022-01-14T15:41:36.62","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"0847b543-0847-4494-9fca-857a1ca51a73","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:36.62","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"navn":[{"fornavn":"ARTIG","mellomnavn":null,"etternavn":"SNERK","forkortetNavn":"SNERK ARTIG","originaltNavn":null,"gyldigFraOgMed":"2022-01-14","folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:36.237","gyldighetstidspunkt":"2022-01-14T15:41:36.237","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"44fbf7a6-6885-48ad-a303-e9d90fa4567f","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:36.237","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"oppholdsadresse":[],"sikkerhetstiltak":[],"sivilstand":[{"type":"UGIFT","gyldigFraOgMed":null,"relatertVedSivilstand":null,"bekreftelsesdato":null,"folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:38.684","gyldighetstidspunkt":"2022-01-14T15:41:38.684","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"2d7f6623-3ba4-44d3-8e04-efced8cd77e3","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:38.684","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"statsborgerskap":[{"land":"NOR","bekreftelsesdato":null,"gyldigFraOgMed":"1972-07-01","gyldigTilOgMed":null,"folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:38.327","gyldighetstidspunkt":"1972-07-01T00:00:00","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"672b293a-b18e-4cd1-9a16-d4a03eb8581d","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:38.326","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"tilrettelagtKommunikasjon":[],"telefonnummer":[],"innflyttingTilNorge":[{"fraflyttingsland":"BEL","fraflyttingsstedIUtlandet":null,"folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:37.532","gyldighetstidspunkt":"1972-07-01T00:00:00","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"5345af76-ac03-4461-9d5c-f17c42ea8a32","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:37.532","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"utflyttingFraNorge":[],"vergemaalEllerFremtidsfullmakt":[]},"hentIdenter":{"identer":[{"ident":"01077211027","historisk":false,"gruppe":"FOLKEREGISTERIDENT","metadata":null,"folkeregistermetadata":null},{"ident":"2594819806563","historisk":false,"gruppe":"AKTORID","metadata":null,"folkeregistermetadata":null}]}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING ) ); @@ -504,6 +182,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual(1, pl.size(), 'Expected one person inserted.'); } + /** + * Simple test to ensure tombstones (null values) do not result in a person + */ @isTest static void testTombstoneIsNotInserted() { List kafkaMessages = new List(); @@ -1059,7 +740,6 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { fregIdent.metadata = new PDL_Metadata(); fregIdent.metadata.historisk = false; porthos.hentPerson.folkeregisteridentifikator.add(fregIdent); - //KafkaMessage__c message1 = createKafkaMessageHelper(createBaseKafkaPerson('1122334455777'), '1122334455777', true); KafkaMessage__c message1 = createKafkaMessage('1122334455777', null); KafkaMessage__c message2 = createKafkaMessage('1122334455666', athos); KafkaMessage__c message3 = createKafkaMessage('1122334455666', porthos); @@ -1129,7 +809,6 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { fregIdent.metadata = new PDL_Metadata(); fregIdent.metadata.historisk = false; hardy.hentPerson.folkeregisteridentifikator.add(fregIdent); - // hardy.sikkerhetstiltak = new List(); // looks like this is well deprecated hardy.hentPerson.sikkerhetstiltak = new List(); hardy.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); hardy.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); From ae1649388da028288ef6404fb80d1c910e35969f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 27 Feb 2024 15:13:35 +0100 Subject: [PATCH 065/159] add and fail setBostedVegadresse (test method) --- .../classes/PDL_Bostedsadresse.cls | 1 + .../pdl-apexTypes/classes/PDL_Vegadresse.cls | 7 ++ .../classes/KafkaPdlGtHandlerTest.cls | 73 +++++++++++ .../classes/KafkaPdlPersondokumentHandler.cls | 9 +- .../KafkaPdlPersondokumentHandlerTest.cls | 119 ++++++++++++++++++ 5 files changed, 208 insertions(+), 1 deletion(-) diff --git a/force-app/pdl-apexTypes/classes/PDL_Bostedsadresse.cls b/force-app/pdl-apexTypes/classes/PDL_Bostedsadresse.cls index 4c479cd9..3e63d0f0 100644 --- a/force-app/pdl-apexTypes/classes/PDL_Bostedsadresse.cls +++ b/force-app/pdl-apexTypes/classes/PDL_Bostedsadresse.cls @@ -4,6 +4,7 @@ public with sharing class PDL_Bostedsadresse { public Datetime gyldigFraOgMed{ get;} public Datetime gyldigTilOgMed{ get;} public String coAdressenavn{ get;} + @TestVisible public PDL_Vegadresse vegadresse{ get;} public PDL_Matrikkeladresse matrikkeladresse{ get;} public PDL_UtenlandskAdresse utenlandskAdresse{ get;} diff --git a/force-app/pdl-apexTypes/classes/PDL_Vegadresse.cls b/force-app/pdl-apexTypes/classes/PDL_Vegadresse.cls index 26de84d1..5e913bfb 100644 --- a/force-app/pdl-apexTypes/classes/PDL_Vegadresse.cls +++ b/force-app/pdl-apexTypes/classes/PDL_Vegadresse.cls @@ -1,14 +1,21 @@ public with sharing class PDL_Vegadresse { public Long matrikkelId{ get;} + @TestVisible public String husnummer{ get;} + @TestVisible public String husbokstav{ get;} public String bruksenhetsnummer{ get;} + @TestVisible public String adressenavn{ get;} + @TestVisible public String kommunenummer{ get;} + @TestVisible public String bydelsnummer{ get;} public String tilleggsnavn{ get;} + @TestVisible public String postnummer{ get;} + @TestVisible public PDL_Koordinater koordinater{ get;} public PDL_Vegadresse() { diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index f10d1d9c..4e6de5de 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -19,4 +19,77 @@ private with sharing class KafkaPdlGtHandlerTest { List pl = [SELECT Id from Person__c where INT_ActorId__c = '1017419408436']; Assert.areEqual(1, pl.size(), 'Expected one person inserted.'); } + + /* + @IsTest + static void setGTFromKommunenummer() { + Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); + KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); + kafkaPerson.kommunenummerFraGt = '0301'; + kafkaPerson.bydelsnummerFraGt = '030101'; + + Test.startTest(); + KafkaPDLHandler2 handler = new KafkaPDLHandler2(); + handler.setMunicipalityAndGT(person, kafkaPerson); + Test.stopTest(); + + System.assertEquals( + '0301', + person.INT_GTMunicipalityNumber__c, + 'Expected INT_GTMunicipalityNumber__c to be set' + ); + System.assertEquals('030101', person.INT_GTDistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + System.assertEquals('03', person.INT_RegionNumber__c, 'Expected INT_RegionNumber__c to be set'); + System.assertEquals('0301', person.INT_MunicipalityNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + System.assertEquals('030101', person.INT_DistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + } + + @IsTest + static void setGTFromKommunenummerNoDistrict() { + Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); + KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); + kafkaPerson.kommunenummerFraGt = '0301'; + + Test.startTest(); + KafkaPDLHandler2 handler = new KafkaPDLHandler2(); + handler.setMunicipalityAndGT(person, kafkaPerson); + Test.stopTest(); + + System.assertEquals( + '0301', + person.INT_GTMunicipalityNumber__c, + 'Expected INT_GTMunicipalityNumber__c to be set' + ); + System.assertEquals(null, person.INT_GTDistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + System.assertEquals('03', person.INT_RegionNumber__c, 'Expected INT_RegionNumber__c to be set'); + System.assertEquals('0301', person.INT_MunicipalityNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + System.assertEquals(null, person.INT_DistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + } + + @IsTest + static void setGTFromKommunenummerFromAddressOnly() { + Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); + KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); + kafkaPerson.bostedsadresse.vegadresse.add(new KafkaPerson2.Vegadresse()); + kafkaPerson.bostedsadresse.vegadresse[0].adressenavn = 'Testveien'; + kafkaPerson.bostedsadresse.vegadresse[0].adressenavn = '1'; + kafkaPerson.bostedsadresse.vegadresse[0].adressenavn = 'A'; + kafkaPerson.bostedsadresse.vegadresse[0].postnummer = '0001'; + kafkaPerson.bostedsadresse.vegadresse[0].kommunenummer = '4321'; + kafkaPerson.bostedsadresse.vegadresse[0].bydelsnummer = '030110'; + kafkaPerson.bostedsadresse.vegadresse[0].koordinater = 'x=354424, y=6862099, z=0'; + + Test.startTest(); + KafkaPDLHandler2 handler = new KafkaPDLHandler2(); + handler.setAddress(person, kafkaPerson); + handler.setMunicipalityAndGT(person, kafkaPerson); + Test.stopTest(); + + System.assertEquals(null, person.INT_GTMunicipalityNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + System.assertEquals(null, person.INT_GTDistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + System.assertEquals(null, person.INT_RegionNumber__c, 'Expected INT_RegionNumber__c to be set'); + System.assertEquals('4321', person.INT_MunicipalityNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + System.assertEquals('030110', person.INT_DistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + } + */ } diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index e9f32f44..86b2ae6a 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -402,8 +402,14 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess return person; } + /** + * Set address. + * Appears to require that address protection has _already_ been applied + * to the person object. Seems dangerous. + */ @TestVisible - private void setAddress(Person__c person, KafkaPerson2 kafkaPerson) { + private void setAddress(Person__c person, PDL_HentPerson hentPerson) { + /* if (ADR_BESKYTTELSES_GRADERING.get(person.INT_Confidential__c) <= 2) { // bostedsadresser // assumption: vegadresse has first pri, then ukjentbosted @@ -460,6 +466,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess person.INT_TemporaryMunicipalityNumber__c = kafkaPerson.oppholdsadresse.ukjentBosted[0].bostedskommune; } } + */ } @TestVisible diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index e9b8388a..2cb2178d 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1297,4 +1297,123 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { '' + kafkaMessages[0].CRM_ErrorMessage__c ); } + + /**************** + * TEST ADDRESS * + ***************/ + + @IsTest + static void setBostedVegadresse() { + Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); + KafkaPerson3 kafkaPerson = createBaseKafkaPerson('11223344556'); + PDL_Bostedsadresse bo = new PDL_Bostedsadresse(); + bo.vegadresse = new PDL_Vegadresse(); + bo.vegadresse.adressenavn = 'Testveien'; + bo.vegadresse.husnummer = '1'; + bo.vegadresse.husbokstav = 'A'; + bo.vegadresse.postnummer = '0001'; + bo.vegadresse.kommunenummer = '4321'; + bo.vegadresse.bydelsnummer = '030110'; + bo.vegadresse.koordinater = (PDL_Koordinater)System.JSON.deserialize( + '{"x":354424, "y":6862099, "z":0}', PDL_Koordinater.class); + kafkaPerson.hentPerson.bostedsadresse.add(bo); + + Test.startTest(); + KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); + handler.setAddress(person, kafkaPerson.hentPerson); + Test.stopTest(); + + System.assertEquals( + 'Testveien 1 A', + person.INT_ResidentialAddress__c, + 'Expected residential address to be set correctly' + ); + System.assertEquals('0001', person.INT_ResidentialZipCode__c, 'Expected residential zip code to be set'); + System.assertEquals( + '4321', + person.INT_AddressMunicipalityNumber__c, + 'Expected Address Municipality number to be set' + ); + System.assertEquals( + '030110', + person.INT_AddressDistrictNumber__c, + 'Expected Address District number to be set' + ); + System.assertEquals('x=354424, y=6862099, z=0', person.INT_Coordinates__c, 'Expected coordinates to be set'); + + System.assertEquals(null, person.INT_TemporaryAddress__c, 'Expected INT_TemporaryAddress__c to be null'); + System.assertEquals(null, person.INT_TemporaryZipCode__c, 'Expected INT_TemporaryZipCode__c to be null'); + System.assertEquals( + null, + person.INT_TemporaryMunicipalityNumber__c, + 'Expected INT_TemporaryMunicipalityNumber__c to be null' + ); + System.assertEquals( + null, + person.INT_TemporaryCoordinates__c, + 'Expected INT_TemporaryCoordinates__c to be null' + ); + System.assertEquals( + null, + person.INT_TemporaryCountryCode__c, + 'Expected INT_TemporaryCountryCode__c to be null' + ); + } + + /* + @IsTest + static void setOppholdVegadresse() { + Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); + KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); + kafkaPerson.oppholdsadresse.vegadresse.add(new KafkaPerson2.Vegadresse()); + kafkaPerson.oppholdsadresse.vegadresse[0].adressenavn = 'Testveien'; + kafkaPerson.oppholdsadresse.vegadresse[0].husnummer = '1'; + kafkaPerson.oppholdsadresse.vegadresse[0].husbokstav = 'A'; + kafkaPerson.oppholdsadresse.vegadresse[0].postnummer = '0001'; + kafkaPerson.oppholdsadresse.vegadresse[0].kommunenummer = '4321'; + kafkaPerson.oppholdsadresse.vegadresse[0].bydelsnummer = '030110'; + kafkaPerson.oppholdsadresse.vegadresse[0].koordinater = 'x=354424, y=6862099, z=0'; + + Test.startTest(); + KafkaPDLHandler2 handler = new KafkaPDLHandler2(); + handler.setAddress(person, kafkaPerson); + Test.stopTest(); + + System.assertEquals(null, person.INT_ResidentialAddress__c, 'Expected INT_ResidentialAddress__c to be null'); + System.assertEquals(null, person.INT_ResidentialZipCode__c, 'Expected INT_ResidentialZipCode__c to be null'); + System.assertEquals( + null, + person.INT_AddressMunicipalityNumber__c, + 'Expected INT_AddressMunicipalityNumber__c to be null' + ); + System.assertEquals( + null, + person.INT_AddressDistrictNumber__c, + 'Expected INT_AddressDistrictNumber__c to be null' + ); + System.assertEquals(null, person.INT_Coordinates__c, 'Expected INT_Coordinates__c to be null'); + + System.assertEquals( + 'Testveien 1 A', + person.INT_TemporaryAddress__c, + 'Expected residential address to be set correctly' + ); + System.assertEquals('0001', person.INT_TemporaryZipCode__c, 'Expected residential zip code to be set'); + System.assertEquals( + '4321', + person.INT_TemporaryMunicipalityNumber__c, + 'Expected Address Municipality number to be set' + ); + System.assertEquals( + 'x=354424, y=6862099, z=0', + person.INT_TemporaryCoordinates__c, + 'Expected coordinates to be set' + ); + System.assertEquals( + null, + person.INT_TemporaryCountryCode__c, + 'Expected INT_TemporaryCountryCode__c to be null' + ); + } + */ } From 717466465508211f18c77de535c9fb7358a5cb06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 27 Feb 2024 19:06:30 +0100 Subject: [PATCH 066/159] minor --- .../KafkaPdlPersondokumentHandlerTest.cls | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 2cb2178d..c0d4a3f2 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1302,6 +1302,10 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { * TEST ADDRESS * ***************/ + /** + * Tests that setAddress combines fields from kafka person correctly. + * TODO: also test that setAddress is actually called. + */ @IsTest static void setBostedVegadresse() { Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); @@ -1323,41 +1327,28 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { handler.setAddress(person, kafkaPerson.hentPerson); Test.stopTest(); - System.assertEquals( + Assert.areEqual( 'Testveien 1 A', person.INT_ResidentialAddress__c, 'Expected residential address to be set correctly' ); - System.assertEquals('0001', person.INT_ResidentialZipCode__c, 'Expected residential zip code to be set'); - System.assertEquals( + Assert.areEqual('0001', person.INT_ResidentialZipCode__c, 'Expected residential zip code to be set'); + Assert.areEqual( '4321', person.INT_AddressMunicipalityNumber__c, 'Expected Address Municipality number to be set' ); - System.assertEquals( + Assert.areEqual( '030110', person.INT_AddressDistrictNumber__c, 'Expected Address District number to be set' ); - System.assertEquals('x=354424, y=6862099, z=0', person.INT_Coordinates__c, 'Expected coordinates to be set'); - - System.assertEquals(null, person.INT_TemporaryAddress__c, 'Expected INT_TemporaryAddress__c to be null'); - System.assertEquals(null, person.INT_TemporaryZipCode__c, 'Expected INT_TemporaryZipCode__c to be null'); - System.assertEquals( - null, - person.INT_TemporaryMunicipalityNumber__c, - 'Expected INT_TemporaryMunicipalityNumber__c to be null' - ); - System.assertEquals( - null, - person.INT_TemporaryCoordinates__c, - 'Expected INT_TemporaryCoordinates__c to be null' - ); - System.assertEquals( - null, - person.INT_TemporaryCountryCode__c, - 'Expected INT_TemporaryCountryCode__c to be null' - ); + Assert.areEqual('x=354424, y=6862099, z=0', person.INT_Coordinates__c, 'Expected coordinates to be set'); + Assert.isNull(person.INT_TemporaryAddress__c); + Assert.isNull(person.INT_TemporaryZipCode__c); + Assert.isNull(person.INT_TemporaryMunicipalityNumber__c); + Assert.isNull(person.INT_TemporaryCoordinates__c); + Assert.isNull(person.INT_TemporaryCountryCode__c); } /* From 8802701ba50a24ba6f0d9ab58b012c098f800918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 28 Feb 2024 09:32:09 +0100 Subject: [PATCH 067/159] set road address --- .../classes/KafkaPdlPersondokumentHandler.cls | 130 ++++++++++-------- .../KafkaPdlPersondokumentHandlerTest.cls | 2 + 2 files changed, 75 insertions(+), 57 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 86b2ae6a..018d95bb 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -403,70 +403,81 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * Set address. + * Sets the address. + */ + @TestVisible + private void setAddressFortroligOrUgradert(Person__c person, PDL_HentPerson hentPerson) { + // bostedsadresser + // assumption: vegadresse has first pri, then ukjentbosted + PDL_Bostedsadresse bo = hentPerson.bostedsadresse.size() > 0 ? hentPerson.bostedsadresse[0] : null; + if (bo?.vegadresse != null) { + person.INT_ResidentialAddress__c = addressCreator( + new List{ + bo.vegadresse.adressenavn, + bo.vegadresse.husnummer, + bo.vegadresse.husbokstav + } + ); + /* + person.INT_ResidentialZipCode__c = kafkaPerson.bostedsadresse.vegadresse[0].postnummer; + person.INT_AddressMunicipalityNumber__c = kafkaPerson.bostedsadresse.vegadresse[0].kommunenummer; + person.INT_AddressDistrictNumber__c = kafkaPerson.bostedsadresse.vegadresse[0].bydelsnummer; + person.INT_Coordinates__c = kafkaPerson.bostedsadresse.vegadresse[0].koordinater; + } else if (kafkaPerson.bostedsadresse.matrikkeladresse.size() > 0) { + person.INT_ResidentialZipCode__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].postnummer; + person.INT_AddressMunicipalityNumber__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].kommunenummer; + person.INT_AddressDistrictNumber__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].bydelsnummer; + person.INT_Coordinates__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].koordinater; + */ + } + + /* + // oppholdsadresser + // assumption: vegadresse has first pri, then utenlandskAdresse, then ukjentbosted + if (kafkaPerson.oppholdsadresse.vegadresse.size() > 0) { + person.INT_TemporaryAddress__c = addressCreator( + new List{ + kafkaPerson.oppholdsadresse.vegadresse[0].adressenavn, + kafkaPerson.oppholdsadresse.vegadresse[0].husnummer, + kafkaPerson.oppholdsadresse.vegadresse[0].husbokstav + } + ); + person.INT_TemporaryZipCode__c = kafkaPerson.oppholdsadresse.vegadresse[0].postnummer; + person.INT_TemporaryMunicipalityNumber__c = kafkaPerson.oppholdsadresse.vegadresse[0].kommunenummer; + person.INT_TemporaryCoordinates__c = kafkaPerson.oppholdsadresse.vegadresse[0].koordinater; + } else if (kafkaPerson.oppholdsadresse.matrikkeladresse.size() > 0) { + person.INT_TemporaryZipCode__c = kafkaPerson.oppholdsadresse.matrikkeladresse[0].postnummer; + person.INT_TemporaryMunicipalityNumber__c = kafkaPerson.oppholdsadresse.matrikkeladresse[0] + .kommunenummer; + person.INT_TemporaryCoordinates__c = kafkaPerson.oppholdsadresse.matrikkeladresse[0].koordinater; + } else if (kafkaPerson.oppholdsadresse.utenlandskAdresse.size() > 0) { + person.INT_TemporaryAddress__c = addressCreator( + new List{ + kafkaPerson.oppholdsadresse.utenlandskAdresse[0].adressenavnNummer, + kafkaPerson.oppholdsadresse.utenlandskAdresse[0].bygningEtasjeLeilighet, + kafkaPerson.oppholdsadresse.utenlandskAdresse[0].postboksNummerNavn, + kafkaPerson.oppholdsadresse.utenlandskAdresse[0].postkode, + kafkaPerson.oppholdsadresse.utenlandskAdresse[0].bysted, + kafkaPerson.oppholdsadresse.utenlandskAdresse[0].regionDistriktOmraade + } + ); // max 255 symbols might be an issue + person.INT_TemporaryCountryCode__c = kafkaPerson.oppholdsadresse.utenlandskAdresse[0].landkode.left(3); + } else if (kafkaPerson.oppholdsadresse.ukjentBosted.size() > 0) { + person.INT_TemporaryMunicipalityNumber__c = kafkaPerson.oppholdsadresse.ukjentBosted[0].bostedskommune; + } + */ + } + + /** + * Sets the address, if appropriate. * Appears to require that address protection has _already_ been applied * to the person object. Seems dangerous. */ @TestVisible private void setAddress(Person__c person, PDL_HentPerson hentPerson) { - /* if (ADR_BESKYTTELSES_GRADERING.get(person.INT_Confidential__c) <= 2) { - // bostedsadresser - // assumption: vegadresse has first pri, then ukjentbosted - if (kafkaPerson.bostedsadresse.vegadresse.size() > 0) { - person.INT_ResidentialAddress__c = addressCreator( - new List{ - kafkaPerson.bostedsadresse.vegadresse[0].adressenavn, - kafkaPerson.bostedsadresse.vegadresse[0].husnummer, - kafkaPerson.bostedsadresse.vegadresse[0].husbokstav - } - ); - person.INT_ResidentialZipCode__c = kafkaPerson.bostedsadresse.vegadresse[0].postnummer; - person.INT_AddressMunicipalityNumber__c = kafkaPerson.bostedsadresse.vegadresse[0].kommunenummer; - person.INT_AddressDistrictNumber__c = kafkaPerson.bostedsadresse.vegadresse[0].bydelsnummer; - person.INT_Coordinates__c = kafkaPerson.bostedsadresse.vegadresse[0].koordinater; - } else if (kafkaPerson.bostedsadresse.matrikkeladresse.size() > 0) { - person.INT_ResidentialZipCode__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].postnummer; - person.INT_AddressMunicipalityNumber__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].kommunenummer; - person.INT_AddressDistrictNumber__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].bydelsnummer; - person.INT_Coordinates__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].koordinater; - } - - // oppholdsadresser - // assumption: vegadresse has first pri, then utenlandskAdresse, then ukjentbosted - if (kafkaPerson.oppholdsadresse.vegadresse.size() > 0) { - person.INT_TemporaryAddress__c = addressCreator( - new List{ - kafkaPerson.oppholdsadresse.vegadresse[0].adressenavn, - kafkaPerson.oppholdsadresse.vegadresse[0].husnummer, - kafkaPerson.oppholdsadresse.vegadresse[0].husbokstav - } - ); - person.INT_TemporaryZipCode__c = kafkaPerson.oppholdsadresse.vegadresse[0].postnummer; - person.INT_TemporaryMunicipalityNumber__c = kafkaPerson.oppholdsadresse.vegadresse[0].kommunenummer; - person.INT_TemporaryCoordinates__c = kafkaPerson.oppholdsadresse.vegadresse[0].koordinater; - } else if (kafkaPerson.oppholdsadresse.matrikkeladresse.size() > 0) { - person.INT_TemporaryZipCode__c = kafkaPerson.oppholdsadresse.matrikkeladresse[0].postnummer; - person.INT_TemporaryMunicipalityNumber__c = kafkaPerson.oppholdsadresse.matrikkeladresse[0] - .kommunenummer; - person.INT_TemporaryCoordinates__c = kafkaPerson.oppholdsadresse.matrikkeladresse[0].koordinater; - } else if (kafkaPerson.oppholdsadresse.utenlandskAdresse.size() > 0) { - person.INT_TemporaryAddress__c = addressCreator( - new List{ - kafkaPerson.oppholdsadresse.utenlandskAdresse[0].adressenavnNummer, - kafkaPerson.oppholdsadresse.utenlandskAdresse[0].bygningEtasjeLeilighet, - kafkaPerson.oppholdsadresse.utenlandskAdresse[0].postboksNummerNavn, - kafkaPerson.oppholdsadresse.utenlandskAdresse[0].postkode, - kafkaPerson.oppholdsadresse.utenlandskAdresse[0].bysted, - kafkaPerson.oppholdsadresse.utenlandskAdresse[0].regionDistriktOmraade - } - ); // max 255 symbols might be an issue - person.INT_TemporaryCountryCode__c = kafkaPerson.oppholdsadresse.utenlandskAdresse[0].landkode.left(3); - } else if (kafkaPerson.oppholdsadresse.ukjentBosted.size() > 0) { - person.INT_TemporaryMunicipalityNumber__c = kafkaPerson.oppholdsadresse.ukjentBosted[0].bostedskommune; - } + setAddressFortroligOrUgradert(person, hentPerson); } - */ } @TestVisible @@ -553,6 +564,11 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess return !String.isBlank(dateToCheck) ? Date.valueOf(dateToCheck) : null; } + /** + * Joins a list of strings with a single space between each nonempty string. + * Also checks that... each element of the string is <= 255 symbols? + * Strange. + */ @TestVisible private static String addressCreator(List addressFields) { String addressString = ''; diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index c0d4a3f2..ae11a916 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1351,6 +1351,8 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.isNull(person.INT_TemporaryCountryCode__c); } + /* TODO: test that address protection actually works */ + /* @IsTest static void setOppholdVegadresse() { From 1261ca5f8e021ff048c2058c426706d8d392209e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 28 Feb 2024 14:12:36 +0100 Subject: [PATCH 068/159] fix address trimming, factor out stringValidator --- .../classes/KafkaPdlPersondokumentHandler.cls | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 018d95bb..f039f6f9 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -305,9 +305,9 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess // Navn if (hentPerson.navn.size() > 0) { PDL_Navn navn = hentPerson.navn[hentPerson.navn.size() - 1]; - person.INT_FirstName__c = stringValidator(navn.fornavn); - person.INT_MiddleName__c = stringValidator(navn.mellomnavn); - person.INT_LastName__c = stringValidator(navn.etternavn); + person.INT_FirstName__c = navn.fornavn ?? ''; + person.INT_MiddleName__c = navn.mellomnavn ?? ''; + person.INT_LastName__c = navn.etternavn ?? ''; } // folkeregisterpersonstatus @@ -544,16 +544,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess return String.join(interpreterLanguages, ';'); } - /** - * Check that field size limitations of 255 signs is followed and allow empty string - * @param stringToCheck String to check - * @return Empty String checked string with maximum 255 symbols - */ - @TestVisible - private static String stringValidator(String stringToCheck) { - return String.isBlank(stringToCheck) || stringToCheck == null ? '' : stringToCheck.left(255); - } - /** * Check that date has a value (not null or '') * @param dateToCheck Date to check @@ -566,18 +556,17 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess /** * Joins a list of strings with a single space between each nonempty string. - * Also checks that... each element of the string is <= 255 symbols? - * Strange. + * Caps output at 255 symbols. */ @TestVisible private static String addressCreator(List addressFields) { String addressString = ''; for (String addressField : addressFields) { - if (stringValidator(addressField) != '') { - addressString += stringValidator(addressField) + ' '; + if (String.isNotBlank(addressField)) { + addressString += addressField + ' '; } } - return addressString.removeEnd(' '); + return addressString.removeEnd(' ').left(255); } /** From 06be87b7a30fbcd8c572ab3d18b26df49c257fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 28 Feb 2024 16:21:48 +0100 Subject: [PATCH 069/159] add some more fields INT_ResidentialZipCode__c, INT_AddressMunicipalityNumber__c, and INT_AddressDistrictNumber__c --- .../classes/KafkaPdlPersondokumentHandler.cls | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index f039f6f9..bbc115f3 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -418,17 +418,18 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess bo.vegadresse.husbokstav } ); - /* - person.INT_ResidentialZipCode__c = kafkaPerson.bostedsadresse.vegadresse[0].postnummer; - person.INT_AddressMunicipalityNumber__c = kafkaPerson.bostedsadresse.vegadresse[0].kommunenummer; - person.INT_AddressDistrictNumber__c = kafkaPerson.bostedsadresse.vegadresse[0].bydelsnummer; - person.INT_Coordinates__c = kafkaPerson.bostedsadresse.vegadresse[0].koordinater; - } else if (kafkaPerson.bostedsadresse.matrikkeladresse.size() > 0) { + person.INT_ResidentialZipCode__c = bo.vegadresse.postnummer; + person.INT_AddressMunicipalityNumber__c = bo.vegadresse.kommunenummer; + person.INT_AddressDistrictNumber__c = bo.vegadresse.bydelsnummer; + /* + person.INT_Coordinates__c = bo.vegadresse.koordinater; + } + else if (kafkaPerson.bostedsadresse.matrikkeladresse.size() > 0) { person.INT_ResidentialZipCode__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].postnummer; person.INT_AddressMunicipalityNumber__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].kommunenummer; person.INT_AddressDistrictNumber__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].bydelsnummer; person.INT_Coordinates__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].koordinater; - */ + */ } /* From d9ae791ec937c331a90853faacf761341985da6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Thu, 29 Feb 2024 13:44:54 +0100 Subject: [PATCH 070/159] add INT_Coordinates__c, now doubles, not strings Note: it appears no one uses this data anyway. --- .gitignore | 1 + .../pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 5 ++++- .../classes/KafkaPdlPersondokumentHandlerTest.cls | 4 +--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 8dc1936c..931d65f6 100755 --- a/.gitignore +++ b/.gitignore @@ -50,5 +50,6 @@ install.cmd # misc .*.sw? +*.vim TAGS tags diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index bbc115f3..ab01516e 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -421,8 +421,11 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess person.INT_ResidentialZipCode__c = bo.vegadresse.postnummer; person.INT_AddressMunicipalityNumber__c = bo.vegadresse.kommunenummer; person.INT_AddressDistrictNumber__c = bo.vegadresse.bydelsnummer; + person.INT_Coordinates__c = String.format('x={0}, y={1}, z={2}', new List{ + bo.vegadresse.koordinater.x, + bo.vegadresse.koordinater.y, + bo.vegadresse.koordinater.z}); /* - person.INT_Coordinates__c = bo.vegadresse.koordinater; } else if (kafkaPerson.bostedsadresse.matrikkeladresse.size() > 0) { person.INT_ResidentialZipCode__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].postnummer; diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index ae11a916..ddd3dba4 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1321,12 +1321,10 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { bo.vegadresse.koordinater = (PDL_Koordinater)System.JSON.deserialize( '{"x":354424, "y":6862099, "z":0}', PDL_Koordinater.class); kafkaPerson.hentPerson.bostedsadresse.add(bo); - Test.startTest(); KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); handler.setAddress(person, kafkaPerson.hentPerson); Test.stopTest(); - Assert.areEqual( 'Testveien 1 A', person.INT_ResidentialAddress__c, @@ -1343,7 +1341,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { person.INT_AddressDistrictNumber__c, 'Expected Address District number to be set' ); - Assert.areEqual('x=354424, y=6862099, z=0', person.INT_Coordinates__c, 'Expected coordinates to be set'); + Assert.areEqual('x=354424.0, y=6862099.0, z=0.0', person.INT_Coordinates__c, 'Expected coordinates to be set'); Assert.isNull(person.INT_TemporaryAddress__c); Assert.isNull(person.INT_TemporaryZipCode__c); Assert.isNull(person.INT_TemporaryMunicipalityNumber__c); From 36953b375f532c49e97c2aa48d23b5236e4bbbe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Thu, 29 Feb 2024 13:55:07 +0100 Subject: [PATCH 071/159] drop class/methods for Key, which is now a string --- .../classes/KafkaPdlPersondokumentHandler.cls | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index ab01516e..d7368df7 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -927,18 +927,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess message.CRM_Status__c = status; } - private Key getKeyFromBase64(String encodedString) { - return (Key) System.JSON.deserialize( - KafkaMessageUtils.base64ULSafeDecode(encodedString).toString(), - Key.class - ); - } - - private class Key { - final String aktoer_id; - final Boolean tombstone; - } - public class PdlListContainsTooManyEntriesException extends Exception { } From 2f5f3f51589db300cd7e7166b91d8b6bbd47f1d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Thu, 29 Feb 2024 19:09:32 +0100 Subject: [PATCH 072/159] add test for cadastral ("matrikkel-") address --- .../classes/PDL_Matrikkeladresse.cls | 1 + .../KafkaPdlPersondokumentHandlerTest.cls | 28 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/force-app/pdl-apexTypes/classes/PDL_Matrikkeladresse.cls b/force-app/pdl-apexTypes/classes/PDL_Matrikkeladresse.cls index ec2d8ae0..851c1211 100644 --- a/force-app/pdl-apexTypes/classes/PDL_Matrikkeladresse.cls +++ b/force-app/pdl-apexTypes/classes/PDL_Matrikkeladresse.cls @@ -1,6 +1,7 @@ public with sharing class PDL_Matrikkeladresse { public Long matrikkelId{ get;} + public String bydelsnummer{ get;} public String bruksenhetsnummer{ get;} public String tilleggsnavn{ get;} public String postnummer{ get;} diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index ddd3dba4..6093c7ba 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1309,7 +1309,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { @IsTest static void setBostedVegadresse() { Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); - KafkaPerson3 kafkaPerson = createBaseKafkaPerson('11223344556'); + KafkaPerson3 kafkaPerson = createBaseKafkaPerson('1122334455666'); PDL_Bostedsadresse bo = new PDL_Bostedsadresse(); bo.vegadresse = new PDL_Vegadresse(); bo.vegadresse.adressenavn = 'Testveien'; @@ -1349,6 +1349,32 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.isNull(person.INT_TemporaryCountryCode__c); } + /** + * Test secondary address, and that setAddress is actually called. + */ + @IsTest + static void setBostedCadastralAddress() { + List kafkaMessages = new List(); + kafkaMessages.add( + new KafkaMessage__c( + CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Key__c = '9011710145110', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"hentPerson":{"vergemaalEllerFremtidsfullmakt":[],"utflyttingFraNorge":[],"utenlandskIdentifikasjonsnummer":[],"tilrettelagtKommunikasjon":[],"telefonnummer":[],"statsborgerskap":[],"sivilstand":[],"sikkerhetstiltak":[],"oppholdsadresse":[],"opphold":[],"navn":[{"etternavn":"TRESTRESEN"}],"kontaktinformasjonForDoedsbo":[],"kontaktadresse":[],"kjoenn":[],"innflyttingTilNorge":[],"identitetsgrunnlag":[],"fullmakt":[],"foreldreansvar":[],"forelderBarnRelasjon":[],"folkeregisterpersonstatus":[{"status":"bosatt"}],"folkeregisteridentifikator":[],"foedsel":[],"doedsfall":[],"doedfoedtBarn":[],"deltBosted":[],"bostedsadresse":[{"matrikkeladresse":{"postnummer":"4096","kommunenummer":"8192","bydelsnummer":"262144","koordinater":{"x":4806741,"y":1286234,"z":-1}}}],"adressebeskyttelse":[]},"hentIdenter":{"identer":[{"ident":9011710145110,"historisk":false,"gruppe":"AKTORID"},{"ident":90117101451,"historisk":false,"gruppe":"FOLKEREGISTERIDENT"}]}}')), + CRM_Status__c = KafkaMessageService.STATUS_PENDING + ) + ); + System.Test.startTest(); + KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); + handler.processMessages(kafkaMessages); + System.Test.stopTest(); + Person__c p = [SELECT Id, INT_ResidentialZipCode__c, INT_AddressMunicipalityNumber__c, INT_AddressDistrictNumber__c, INT_Coordinates__c FROM Person__c][0]; + Assert.areEqual('4096', p.INT_ResidentialZipCode__c); + Assert.areEqual('8192', p.INT_AddressMunicipalityNumber__c); + Assert.areEqual('262144', p.INT_AddressDistrictNumber__c); + Assert.areEqual('x=4806741.0, y=1286234.0, z=-1.0', p.INT_Coordinates__c); + } + + /* TODO: test that address protection actually works */ /* From ca54cc231c674270ed3dcd911a2308db01a93289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Thu, 29 Feb 2024 22:52:20 +0100 Subject: [PATCH 073/159] pass setBostedCadastralAddress --- .../classes/KafkaPdlPersondokumentHandler.cls | 33 +++++++++++-------- .../KafkaPdlPersondokumentHandlerTest.cls | 1 - 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index d7368df7..1e825efa 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -329,10 +329,10 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess // sikkerhetstiltak person.INT_SecurityMeasures__c = JSON.serialize(kafkaPerson.hentPerson.sikkerhetstiltak); - /* // adresse - setAddress(person, kafkaPerson); + setAddress(person, kafkaPerson.hentPerson); + /* setMunicipalityAndGT(person, kafkaPerson); */ @@ -402,6 +402,18 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess return person; } + /** + * Create a readable string from a coordinate object. + * Note: coordinates are currently useless, but PDL may implement them + * in the future. + */ + private String formatCoordinates(PDL_Koordinater k) { + return String.format('x={0}, y={1}, z={2}', new List{ + k.x, + k.y, + k.z}); + } + /** * Sets the address. */ @@ -421,18 +433,13 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess person.INT_ResidentialZipCode__c = bo.vegadresse.postnummer; person.INT_AddressMunicipalityNumber__c = bo.vegadresse.kommunenummer; person.INT_AddressDistrictNumber__c = bo.vegadresse.bydelsnummer; - person.INT_Coordinates__c = String.format('x={0}, y={1}, z={2}', new List{ - bo.vegadresse.koordinater.x, - bo.vegadresse.koordinater.y, - bo.vegadresse.koordinater.z}); - /* + person.INT_Coordinates__c = formatCoordinates(bo.vegadresse.koordinater); } - else if (kafkaPerson.bostedsadresse.matrikkeladresse.size() > 0) { - person.INT_ResidentialZipCode__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].postnummer; - person.INT_AddressMunicipalityNumber__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].kommunenummer; - person.INT_AddressDistrictNumber__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].bydelsnummer; - person.INT_Coordinates__c = kafkaPerson.bostedsadresse.matrikkeladresse[0].koordinater; - */ + else if (bo?.matrikkeladresse != null) { + person.INT_ResidentialZipCode__c = bo.matrikkeladresse.postnummer; + person.INT_AddressMunicipalityNumber__c = bo.matrikkeladresse.kommunenummer; + person.INT_AddressDistrictNumber__c = bo.matrikkeladresse.bydelsnummer; + person.INT_Coordinates__c = formatCoordinates(bo.matrikkeladresse.koordinater); } /* diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 6093c7ba..4d59ba59 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1304,7 +1304,6 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { /** * Tests that setAddress combines fields from kafka person correctly. - * TODO: also test that setAddress is actually called. */ @IsTest static void setBostedVegadresse() { From a0bd427fe2c157269dd65efe6fc10e4abf7a6bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Thu, 29 Feb 2024 23:41:35 +0100 Subject: [PATCH 074/159] add test for address protection --- .../KafkaPdlPersondokumentHandlerTest.cls | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 4d59ba59..b3ce5718 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1371,10 +1371,29 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('8192', p.INT_AddressMunicipalityNumber__c); Assert.areEqual('262144', p.INT_AddressDistrictNumber__c); Assert.areEqual('x=4806741.0, y=1286234.0, z=-1.0', p.INT_Coordinates__c); - } - + } - /* TODO: test that address protection actually works */ + /** + * Tests that address protection actually works + */ + @IsTest + static void dontSetProtectedAddress() { + List kafkaMessages = new List(); + kafkaMessages.add( + new KafkaMessage__c( + CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Key__c = '9011710145110', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"hentPerson":{"vergemaalEllerFremtidsfullmakt":[],"utflyttingFraNorge":[],"utenlandskIdentifikasjonsnummer":[],"tilrettelagtKommunikasjon":[],"telefonnummer":[],"statsborgerskap":[],"sivilstand":[],"sikkerhetstiltak":[],"oppholdsadresse":[],"opphold":[],"navn":[{"etternavn":"TRESTRESEN"}],"kontaktinformasjonForDoedsbo":[],"kontaktadresse":[],"kjoenn":[],"innflyttingTilNorge":[],"identitetsgrunnlag":[],"fullmakt":[],"foreldreansvar":[],"forelderBarnRelasjon":[],"folkeregisterpersonstatus":[{"status":"bosatt"}],"folkeregisteridentifikator":[],"foedsel":[],"doedsfall":[],"doedfoedtBarn":[],"deltBosted":[],"bostedsadresse":[{"matrikkeladresse":{"postnummer":"4096","kommunenummer":"8192","bydelsnummer":"262144","koordinater":{"x":4806741,"y":1286234,"z":-1}}}],"adressebeskyttelse":[{"gradering":"STRENGT_FORTROLIG"}]},"hentIdenter":{"identer":[{"ident":9011710145110,"historisk":false,"gruppe":"AKTORID"},{"ident":90117101451,"historisk":false,"gruppe":"FOLKEREGISTERIDENT"}]}}')), + CRM_Status__c = KafkaMessageService.STATUS_PENDING + ) + ); + System.Test.startTest(); + KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); + handler.processMessages(kafkaMessages); + System.Test.stopTest(); + Person__c p = [SELECT Id, INT_ResidentialZipCode__c, INT_AddressMunicipalityNumber__c, INT_AddressDistrictNumber__c, INT_Coordinates__c FROM Person__c][0]; + Assert.isNull(p.INT_ResidentialZipCode__c); + } /* @IsTest From 792cc21de5113dbf3f246a8f7102cdda0842b2b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Thu, 29 Feb 2024 23:59:06 +0100 Subject: [PATCH 075/159] add test for address of residence --- .../classes/PDL_Oppholdsadresse.cls | 1 + .../KafkaPdlPersondokumentHandlerTest.cls | 63 +++++++------------ 2 files changed, 25 insertions(+), 39 deletions(-) diff --git a/force-app/pdl-apexTypes/classes/PDL_Oppholdsadresse.cls b/force-app/pdl-apexTypes/classes/PDL_Oppholdsadresse.cls index ee5e2931..8a54fb15 100644 --- a/force-app/pdl-apexTypes/classes/PDL_Oppholdsadresse.cls +++ b/force-app/pdl-apexTypes/classes/PDL_Oppholdsadresse.cls @@ -4,6 +4,7 @@ public with sharing class PDL_Oppholdsadresse { public Datetime gyldigTilOgMed{ get;} public String coAdressenavn{ get;} public PDL_UtenlandskAdresse utenlandskAdresse{ get;} + @TestVisible public PDL_Vegadresse vegadresse{ get;} public PDL_Matrikkeladresse matrikkeladresse{ get;} public String oppholdAnnetSted{ get;} diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index b3ce5718..3b20f903 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1391,64 +1391,49 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); handler.processMessages(kafkaMessages); System.Test.stopTest(); - Person__c p = [SELECT Id, INT_ResidentialZipCode__c, INT_AddressMunicipalityNumber__c, INT_AddressDistrictNumber__c, INT_Coordinates__c FROM Person__c][0]; + Person__c p = [SELECT Id, INT_ActorId__c, INT_ResidentialZipCode__c, INT_AddressMunicipalityNumber__c, INT_AddressDistrictNumber__c, INT_Coordinates__c FROM Person__c][0]; + Assert.areEqual('9011710145110', p.INT_ActorId__c); Assert.isNull(p.INT_ResidentialZipCode__c); } - /* @IsTest static void setOppholdVegadresse() { Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); - KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); - kafkaPerson.oppholdsadresse.vegadresse.add(new KafkaPerson2.Vegadresse()); - kafkaPerson.oppholdsadresse.vegadresse[0].adressenavn = 'Testveien'; - kafkaPerson.oppholdsadresse.vegadresse[0].husnummer = '1'; - kafkaPerson.oppholdsadresse.vegadresse[0].husbokstav = 'A'; - kafkaPerson.oppholdsadresse.vegadresse[0].postnummer = '0001'; - kafkaPerson.oppholdsadresse.vegadresse[0].kommunenummer = '4321'; - kafkaPerson.oppholdsadresse.vegadresse[0].bydelsnummer = '030110'; - kafkaPerson.oppholdsadresse.vegadresse[0].koordinater = 'x=354424, y=6862099, z=0'; - + KafkaPerson3 kafkaPerson = createBaseKafkaPerson('11223344556'); + PDL_Oppholdsadresse opphold = new PDL_Oppholdsadresse(); + opphold.vegadresse = new PDL_Vegadresse(); + opphold.vegadresse.adressenavn = 'Testveien'; + opphold.vegadresse.husnummer = '1'; + opphold.vegadresse.husbokstav = 'A'; + opphold.vegadresse.postnummer = '0001'; + opphold.vegadresse.kommunenummer = '4321'; + opphold.vegadresse.bydelsnummer = '030110'; + opphold.vegadresse.koordinater = (PDL_Koordinater)System.JSON.deserialize( + '{"x":354424, "y":6862099, "z":0}', PDL_Koordinater.class); Test.startTest(); - KafkaPDLHandler2 handler = new KafkaPDLHandler2(); - handler.setAddress(person, kafkaPerson); + KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); + handler.setAddress(person, kafkaPerson.hentPerson); Test.stopTest(); - - System.assertEquals(null, person.INT_ResidentialAddress__c, 'Expected INT_ResidentialAddress__c to be null'); - System.assertEquals(null, person.INT_ResidentialZipCode__c, 'Expected INT_ResidentialZipCode__c to be null'); - System.assertEquals( - null, - person.INT_AddressMunicipalityNumber__c, - 'Expected INT_AddressMunicipalityNumber__c to be null' - ); - System.assertEquals( - null, - person.INT_AddressDistrictNumber__c, - 'Expected INT_AddressDistrictNumber__c to be null' - ); - System.assertEquals(null, person.INT_Coordinates__c, 'Expected INT_Coordinates__c to be null'); - - System.assertEquals( + Assert.isNull(person.INT_ResidentialAddress__c); + Assert.isNull(person.INT_ResidentialZipCode__c); + Assert.isNull(person.INT_AddressMunicipalityNumber__c); + Assert.isNull(person.INT_Coordinates__c); + Assert.areEqual( 'Testveien 1 A', person.INT_TemporaryAddress__c, 'Expected residential address to be set correctly' ); - System.assertEquals('0001', person.INT_TemporaryZipCode__c, 'Expected residential zip code to be set'); - System.assertEquals( + Assert.areEqual('0001', person.INT_TemporaryZipCode__c, 'Expected residential zip code to be set'); + Assert.areEqual( '4321', person.INT_TemporaryMunicipalityNumber__c, 'Expected Address Municipality number to be set' ); - System.assertEquals( + Assert.areEqual( 'x=354424, y=6862099, z=0', person.INT_TemporaryCoordinates__c, 'Expected coordinates to be set' ); - System.assertEquals( - null, - person.INT_TemporaryCountryCode__c, - 'Expected INT_TemporaryCountryCode__c to be null' - ); + Assert.isNull(person.INT_TemporaryCountryCode__c); } - */ } From 9448e48247c4010bc34da5c2b943d1dd2871b2a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 1 Mar 2024 14:54:58 +0100 Subject: [PATCH 076/159] remove misleading error messages --- .../KafkaPdlPersondokumentHandlerTest.cls | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 3b20f903..891a25e8 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1418,22 +1418,10 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.isNull(person.INT_ResidentialZipCode__c); Assert.isNull(person.INT_AddressMunicipalityNumber__c); Assert.isNull(person.INT_Coordinates__c); - Assert.areEqual( - 'Testveien 1 A', - person.INT_TemporaryAddress__c, - 'Expected residential address to be set correctly' - ); - Assert.areEqual('0001', person.INT_TemporaryZipCode__c, 'Expected residential zip code to be set'); - Assert.areEqual( - '4321', - person.INT_TemporaryMunicipalityNumber__c, - 'Expected Address Municipality number to be set' - ); - Assert.areEqual( - 'x=354424, y=6862099, z=0', - person.INT_TemporaryCoordinates__c, - 'Expected coordinates to be set' - ); + Assert.areEqual('Testveien 1 A', person.INT_TemporaryAddress__c); + Assert.areEqual('0001', person.INT_TemporaryZipCode__c); + Assert.areEqual('4321',person.INT_TemporaryMunicipalityNumber__c); + Assert.areEqual('x=354424, y=6862099, z=0',person.INT_TemporaryCoordinates__c); Assert.isNull(person.INT_TemporaryCountryCode__c); } } From 0339f315fc2e62ca88dd8f6552db61995ec3d4d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 1 Mar 2024 19:20:19 +0100 Subject: [PATCH 077/159] pass setOppholdVegadresse --- .../classes/PDL_Oppholdsadresse.cls | 1 + .../classes/KafkaPdlPersondokumentHandler.cls | 46 +++++++++---------- .../KafkaPdlPersondokumentHandlerTest.cls | 6 ++- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/force-app/pdl-apexTypes/classes/PDL_Oppholdsadresse.cls b/force-app/pdl-apexTypes/classes/PDL_Oppholdsadresse.cls index 8a54fb15..07e646de 100644 --- a/force-app/pdl-apexTypes/classes/PDL_Oppholdsadresse.cls +++ b/force-app/pdl-apexTypes/classes/PDL_Oppholdsadresse.cls @@ -7,6 +7,7 @@ public with sharing class PDL_Oppholdsadresse { @TestVisible public PDL_Vegadresse vegadresse{ get;} public PDL_Matrikkeladresse matrikkeladresse{ get;} + public PDL_UkjentBosted ukjentBosted{ get;} public String oppholdAnnetSted{ get;} public PDL_Folkeregistermetadata folkeregistermetadata{ get;} public PDL_Metadata metadata{ get;} diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 1e825efa..b8a01aac 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -442,41 +442,39 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess person.INT_Coordinates__c = formatCoordinates(bo.matrikkeladresse.koordinater); } - /* // oppholdsadresser // assumption: vegadresse has first pri, then utenlandskAdresse, then ukjentbosted - if (kafkaPerson.oppholdsadresse.vegadresse.size() > 0) { + PDL_Oppholdsadresse opphold = hentPerson.oppholdsadresse.size() > 0 ? hentPerson.oppholdsadresse[0] : null; + if (opphold?.vegadresse != null) { person.INT_TemporaryAddress__c = addressCreator( new List{ - kafkaPerson.oppholdsadresse.vegadresse[0].adressenavn, - kafkaPerson.oppholdsadresse.vegadresse[0].husnummer, - kafkaPerson.oppholdsadresse.vegadresse[0].husbokstav + opphold.vegadresse.adressenavn, + opphold.vegadresse.husnummer, + opphold.vegadresse.husbokstav } ); - person.INT_TemporaryZipCode__c = kafkaPerson.oppholdsadresse.vegadresse[0].postnummer; - person.INT_TemporaryMunicipalityNumber__c = kafkaPerson.oppholdsadresse.vegadresse[0].kommunenummer; - person.INT_TemporaryCoordinates__c = kafkaPerson.oppholdsadresse.vegadresse[0].koordinater; - } else if (kafkaPerson.oppholdsadresse.matrikkeladresse.size() > 0) { - person.INT_TemporaryZipCode__c = kafkaPerson.oppholdsadresse.matrikkeladresse[0].postnummer; - person.INT_TemporaryMunicipalityNumber__c = kafkaPerson.oppholdsadresse.matrikkeladresse[0] - .kommunenummer; - person.INT_TemporaryCoordinates__c = kafkaPerson.oppholdsadresse.matrikkeladresse[0].koordinater; - } else if (kafkaPerson.oppholdsadresse.utenlandskAdresse.size() > 0) { + person.INT_TemporaryZipCode__c = opphold.vegadresse.postnummer; + person.INT_TemporaryMunicipalityNumber__c = opphold.vegadresse.kommunenummer; + person.INT_TemporaryCoordinates__c = formatCoordinates(opphold.vegadresse.koordinater); + } else if (opphold?.matrikkeladresse != null) { + person.INT_TemporaryZipCode__c = opphold.matrikkeladresse.postnummer; + person.INT_TemporaryMunicipalityNumber__c = opphold.matrikkeladresse.kommunenummer; + person.INT_TemporaryCoordinates__c = formatCoordinates(opphold.matrikkeladresse.koordinater); + } else if (opphold?.utenlandskAdresse != null) { person.INT_TemporaryAddress__c = addressCreator( new List{ - kafkaPerson.oppholdsadresse.utenlandskAdresse[0].adressenavnNummer, - kafkaPerson.oppholdsadresse.utenlandskAdresse[0].bygningEtasjeLeilighet, - kafkaPerson.oppholdsadresse.utenlandskAdresse[0].postboksNummerNavn, - kafkaPerson.oppholdsadresse.utenlandskAdresse[0].postkode, - kafkaPerson.oppholdsadresse.utenlandskAdresse[0].bysted, - kafkaPerson.oppholdsadresse.utenlandskAdresse[0].regionDistriktOmraade + opphold.utenlandskAdresse.adressenavnNummer, + opphold.utenlandskAdresse.bygningEtasjeLeilighet, + opphold.utenlandskAdresse.postboksNummerNavn, + opphold.utenlandskAdresse.postkode, + opphold.utenlandskAdresse.bysted, + opphold.utenlandskAdresse.regionDistriktOmraade } ); // max 255 symbols might be an issue - person.INT_TemporaryCountryCode__c = kafkaPerson.oppholdsadresse.utenlandskAdresse[0].landkode.left(3); - } else if (kafkaPerson.oppholdsadresse.ukjentBosted.size() > 0) { - person.INT_TemporaryMunicipalityNumber__c = kafkaPerson.oppholdsadresse.ukjentBosted[0].bostedskommune; + person.INT_TemporaryCountryCode__c = opphold.utenlandskAdresse.landkode.left(3); + } else if (opphold?.ukjentBosted != null) { + person.INT_TemporaryMunicipalityNumber__c = opphold.ukjentBosted.bostedskommune; } - */ } /** diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 891a25e8..aa43e3c7 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1396,6 +1396,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.isNull(p.INT_ResidentialZipCode__c); } + /** + * Tests temporary address + */ @IsTest static void setOppholdVegadresse() { Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); @@ -1410,6 +1413,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { opphold.vegadresse.bydelsnummer = '030110'; opphold.vegadresse.koordinater = (PDL_Koordinater)System.JSON.deserialize( '{"x":354424, "y":6862099, "z":0}', PDL_Koordinater.class); + kafkaPerson.hentPerson.oppholdsadresse.add(opphold); Test.startTest(); KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); handler.setAddress(person, kafkaPerson.hentPerson); @@ -1421,7 +1425,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('Testveien 1 A', person.INT_TemporaryAddress__c); Assert.areEqual('0001', person.INT_TemporaryZipCode__c); Assert.areEqual('4321',person.INT_TemporaryMunicipalityNumber__c); - Assert.areEqual('x=354424, y=6862099, z=0',person.INT_TemporaryCoordinates__c); + Assert.areEqual('x=354424.0, y=6862099.0, z=0.0',person.INT_TemporaryCoordinates__c); Assert.isNull(person.INT_TemporaryCountryCode__c); } } From 043d37592d117f75ed93165cdd6cdbf3523c6a60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 1 Mar 2024 19:53:06 +0100 Subject: [PATCH 078/159] minor --- force-app/pdl-handler/classes/KafkaPdlGtHandler.cls | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index ba5412e7..131038cd 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -5,9 +5,6 @@ */ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer { - public class PdlGtException extends Exception { - } - private void assignIdent(Person__c p, String s) { if(s.length() == 13) { p.INT_ActorId__c = s; @@ -72,4 +69,7 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer List urList = Database.upsert(persons, Person__c.INT_ActorId__c, false); // TODO check for errors, set status to error if so } + + public class PdlGtException extends Exception { + } } From 0d279bfeefa2668ed2c1c1d9bc43d56b715c3743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 5 Mar 2024 18:17:43 +0100 Subject: [PATCH 079/159] GT: test creating a person --- .../classes/KafkaPdlGtHandlerTest.cls | 145 ++++++++++++++++++ .../KafkaPdlPersondokumentHandlerTest.cls | 4 - 2 files changed, 145 insertions(+), 4 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index 4e6de5de..66b05af8 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -1,6 +1,136 @@ +/** + * Tests for KafkaPdlGtHandler, i.e. geografisk tilknytning. + * Assumes KafkaPdlPersondokumentHandler is working as expected, as we will test + * against persons inserted using that. + */ @IsTest private with sharing class KafkaPdlGtHandlerTest { + static void printLogs() { + for (Application_Log__c l : [SELECT Category__c, Log_Level__c, Log_Message__c from Application_Log__c]) { + System.debug('log entry: ' + l.Category__c + ' ' + l.Log_Level__c + ': ' + l.Log_Message__c); + } + } + + /** + * Create a message for inserting a person document. + * See KafkaPdlPersondokumentHandlerTest for more information. + * Explicitly set status; which would otherwise only get called when using + * KafkaMessageService (i.e. upon insert). + */ + private static KafkaMessage__c createPersonDocumentMessage( + String aktorId, + KafkaPerson3 kafkaPerson + ) { + KafkaMessage__c kafkaMessage = new KafkaMessage__c( + CRM_Key__c = aktorId, + CRM_Value__c = (kafkaPerson == null ? + null : + EncodingUtil.base64Encode(Blob.valueOf(JSON.serialize(kafkaPerson)))), + CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Status__c = KafkaMessageService.STATUS_PENDING + ); + return kafkaMessage; + } + + /** + * Inserts kafka person into the database + */ + private static void insertBaseKafkaPerson(String aktorId, KafkaPerson3 kp) { + KafkaMessage__c[] messages = new List{ + createPersonDocumentMessage(aktorId, kp) + }; + KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); + handler.processMessages(messages); + } + + /** + * Initializes KafkaPerson3 as in KafkaPdlPersondokumentHandlerTest and + * creates and inserts a Person based on him. + */ + private static KafkaPerson3 createBaseKafkaPerson(String actorId) { + KafkaPerson3 kp = new KafkaPerson3(); + kp.hentIdenter = new KafkaPerson3.HentIdenter(); + kp.hentIdenter.identer = new List(); + kp.hentPerson = new PDL_HentPerson(); + // just initialise all the lists. + kp.hentPerson.adressebeskyttelse = new List(); + kp.hentPerson.bostedsadresse = new List(); + kp.hentPerson.deltBosted = new List(); + kp.hentPerson.doedfoedtBarn = new List(); + kp.hentPerson.doedsfall = new List(); + kp.hentPerson.foedsel = new List(); + kp.hentPerson.folkeregisteridentifikator = new List(); + kp.hentPerson.folkeregisterpersonstatus = new List(); + kp.hentPerson.forelderBarnRelasjon = new List(); + kp.hentPerson.foreldreansvar = new List(); + kp.hentPerson.fullmakt = new List(); + kp.hentPerson.identitetsgrunnlag = new List(); + kp.hentPerson.innflyttingTilNorge = new List(); + kp.hentPerson.kjoenn = new List(); + kp.hentPerson.kontaktadresse = new List(); + kp.hentPerson.kontaktinformasjonForDoedsbo = new List(); + kp.hentPerson.navn = new List(); + kp.hentPerson.opphold = new List(); + kp.hentPerson.oppholdsadresse = new List(); + kp.hentPerson.sikkerhetstiltak = new List(); + kp.hentPerson.sivilstand = new List(); + kp.hentPerson.statsborgerskap = new List(); + kp.hentPerson.telefonnummer = new List(); + kp.hentPerson.tilrettelagtKommunikasjon = new List(); + kp.hentPerson.utenlandskIdentifikasjonsnummer = new List(); + kp.hentPerson.utflyttingFraNorge = new List(); + kp.hentPerson.vergemaalEllerFremtidsfullmakt = new List(); + // Default values + // Ident + kp.hentIdenter.identer.add(new PDL_IdentInformasjon()); + kp.hentIdenter.identer[0].gruppe = PDL_IdentGruppe.AKTORID; + kp.hentIdenter.identer[0].historisk = false; + kp.hentIdenter.identer[0].ident = actorId; + // Person status + kp.hentPerson.folkeregisterpersonstatus.add(new PDL_Folkeregisterpersonstatus()); + kp.hentPerson.folkeregisterpersonstatus[0].status = 'bosatt'; + // Name + kp.hentPerson.navn.add(new PDL_Navn()); + kp.hentPerson.navn[0].etternavn = 'TRESTRESEN'; + kp.hentPerson.adressebeskyttelse.add(new PDL_Adressebeskyttelse()); + kp.hentPerson.adressebeskyttelse[0].gradering = PDL_AdressebeskyttelseGradering.UGRADERT; + return kp; + } + + /** + * Calls createBaseKafkaPerson(String), and adds a folkeregisterident + */ + private static KafkaPerson3 createBaseKafkaPerson(String actorId, String fregId) { + KafkaPerson3 kp = createBaseKafkaPerson(actorId); + kp.hentIdenter.identer.add(new PDL_IdentInformasjon()); + Integer i = kp.hentIdenter.identer.size() - 1; + kp.hentIdenter.identer[i].ident = fregId; + kp.hentIdenter.identer[i].historisk = false; + kp.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + return kp; + } + + /** + * Initializes KafkaPerson3 as in KafkaPdlPersondokumentHandlerTest and + * creates and inserts a Person based on him. + */ + private static void createAndInsertBaseKafkaPerson(String actorId) { + KafkaPerson3 kp = createBaseKafkaPerson(actorId); + insertBaseKafkaPerson(actorId, kp); + } + + /** + * As the above, but also includes folkeregisterident. + */ + private static void createAndInsertBaseKafkaPerson(String actorId, String fregId) { + KafkaPerson3 kp = createBaseKafkaPerson(actorId, fregId); + insertBaseKafkaPerson(actorId, kp); + } + + /** + * Tests that GT by itself results in a new person. + */ @isTest static void testCreatePersonFromGt() { List kafkaMessages = new List(); @@ -20,6 +150,21 @@ private with sharing class KafkaPdlGtHandlerTest { Assert.areEqual(1, pl.size(), 'Expected one person inserted.'); } + /** + * Tests that we can insert a basic person for further testing. + */ + @isTest + static void testCreatePersonFromPersonDocument() { + createAndInsertBaseKafkaPerson('4398046511104', '68719476736'); + Test.startTest(); + Test.stopTest(); + Person__c[] ps = [SELECT INT_ActorId__c FROM Person__c]; + Assert.areEqual('4398046511104', ps[0].INT_ActorId__c); + } + + /** + * Tests setting GT for existing person. + */ /* @IsTest static void setGTFromKommunenummer() { diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index aa43e3c7..ef2345d7 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -65,9 +65,6 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { kp.hentPerson.utenlandskIdentifikasjonsnummer = new List(); kp.hentPerson.utflyttingFraNorge = new List(); kp.hentPerson.vergemaalEllerFremtidsfullmakt = new List(); - // TODO: decide exactly what to do with these two - //kp.hentPerson.bydelsnummerFraGt = ''; - //kp.hentPerson.kommunenummerFraGt = ''; // Default values // Ident kp.hentIdenter.identer.add(new PDL_IdentInformasjon()); @@ -651,7 +648,6 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { EncodingUtil.base64Encode(Blob.valueOf(JSON.serialize(kafkaPerson)))), CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1' ); - return kafkaMessage; } From b108c8da1aec2bce02fbaefca0a9a84e3761c988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 6 Mar 2024 00:36:08 +0100 Subject: [PATCH 080/159] add passing test for municipality number --- .../classes/KafkaPdlGtHandlerTest.cls | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index 66b05af8..422b02f6 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -165,30 +165,37 @@ private with sharing class KafkaPdlGtHandlerTest { /** * Tests setting GT for existing person. */ - /* @IsTest static void setGTFromKommunenummer() { - Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); - KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); - kafkaPerson.kommunenummerFraGt = '0301'; - kafkaPerson.bydelsnummerFraGt = '030101'; - + createAndInsertBaseKafkaPerson('4398046511104', '68719476736'); + Person__c[] ps = [SELECT INT_ActorId__c, INT_GTMunicipalityNumber__c FROM Person__c]; + Assert.areEqual(1, ps.size()); + Person__c p = ps[0]; + Assert.isNull(p.INT_GTMunicipalityNumber__c); + List kafkaMessages = new List(); + kafkaMessages.add( + new KafkaMessage__c( + CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Key__c = '4398046511104', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"KOMMUNE","gtKommune":"1337","gtBydel":null,"gtLand":null,"regel":"2"}}')), + CRM_Status__c = KafkaMessageService.STATUS_PENDING + ) + ); + KafkaPdlGtHandler handler = new KafkaPdlGtHandler(); Test.startTest(); - KafkaPDLHandler2 handler = new KafkaPDLHandler2(); - handler.setMunicipalityAndGT(person, kafkaPerson); + handler.processMessages(kafkaMessages); Test.stopTest(); - - System.assertEquals( - '0301', - person.INT_GTMunicipalityNumber__c, - 'Expected INT_GTMunicipalityNumber__c to be set' - ); - System.assertEquals('030101', person.INT_GTDistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - System.assertEquals('03', person.INT_RegionNumber__c, 'Expected INT_RegionNumber__c to be set'); - System.assertEquals('0301', person.INT_MunicipalityNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - System.assertEquals('030101', person.INT_DistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + ps = [SELECT INT_ActorId__c, INT_GTMunicipalityNumber__c FROM Person__c]; + Assert.areEqual(1, ps.size()); + p = ps[0]; + Assert.areEqual('1337', p.INT_GTMunicipalityNumber__c); + //System.assertEquals('030101', p.INT_GTDistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + //System.assertEquals('03', p.INT_RegionNumber__c, 'Expected INT_RegionNumber__c to be set'); + //System.assertEquals('0301', p.INT_MunicipalityNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + //System.assertEquals('030101', p.INT_DistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); } + /* @IsTest static void setGTFromKommunenummerNoDistrict() { Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); From ae24b498a783406d4a25c23eb2954ba4d7efe578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 8 Mar 2024 00:29:19 +0100 Subject: [PATCH 081/159] fail minimal test setting GT from district number --- .../pdl-handler/classes/KafkaPdlGtHandler.cls | 27 +++++++++---- .../classes/KafkaPdlGtHandlerTest.cls | 39 +++++++++++++++++++ 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index 131038cd..3b6a2325 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -5,6 +5,8 @@ */ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer { + private LoggerUtility logger; + private void assignIdent(Person__c p, String s) { if(s.length() == 13) { p.INT_ActorId__c = s; @@ -20,6 +22,11 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer } } + private static void setFieldsFromDistrict(Person__c p, PdlGeografiskTilknytning gt) { + p.INT_GTDistrictNumber__c = gt.gtBydel; + p.INT_GTMunicipalityNumber__c = gt.gtBydel.left(4); + } + /** * Transform and map fields from PDL data structure to Person__c SObject * @param person New Person__c SObject record @@ -31,15 +38,14 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer for(String s : kafkaPerson.identer) { assignIdent(person, s); } - - // TODO obviously expand this PdlGeografiskTilknytning gt = kafkaPerson.geografiskTilknytning; - person.INT_GTMunicipalityNumber__c = gt.gtKommune; - - // Ensure that a System User is set as Owner if even if message processing is manually retried by an administrator user - if (KafkaIntegrationCustomSetting.integrationUserId != null) { - person.OwnerId = KafkaIntegrationCustomSetting.integrationUserId; + if (gt.gtType == 'BYDEL') { + logger.info('Setting GT from district', null); + setFieldsFromDistrict(person, gt); + } else { + logger.error('Not setting GT, wtf?', null); } + //person.INT_GTMunicipalityNumber__c = gt.gtKommune; return person; } @@ -58,16 +64,23 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer } public void processMessages(List messages) { + logger = new LoggerUtility('PDL'); List persons = new List(); for (KafkaMessage__c msg : messages) { if (msg.CRM_Status__c == KafkaMessageService.STATUS_PENDING) { Person__c p = createPersonRecord(msg); + // Ensure that a System User is set as Owner if even if message + // processing is manually retried by an administrator user + if (KafkaIntegrationCustomSetting.integrationUserId != null) { + p.OwnerId = KafkaIntegrationCustomSetting.integrationUserId; + } persons.add(p); msg.CRM_Status__c = KafkaMessageService.STATUS_PROCESSED; } } List urList = Database.upsert(persons, Person__c.INT_ActorId__c, false); // TODO check for errors, set status to error if so + logger.publish(); } public class PdlGtException extends Exception { diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index 422b02f6..37c4ffc0 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -195,6 +195,45 @@ private with sharing class KafkaPdlGtHandlerTest { //System.assertEquals('030101', p.INT_DistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); } + /** + * Tests setting _all_ of the fields, based on district number. + * TODO: check if INT_GTMunicipalityNumber__c should perhaps not be set. + * https://pdl-docs.intern.nav.no/ekstern/index.html#geografisk-tilknytning + */ + @IsTest + static void setGTFromBydel() { + createAndInsertBaseKafkaPerson('4398046511104', '68719476736'); + KafkaPdlGtHandler handler = new KafkaPdlGtHandler(); + Test.startTest(); + handler.processMessages(new List{ + new KafkaMessage__c( + CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Key__c = '4398046511104', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), + CRM_Status__c = KafkaMessageService.STATUS_PENDING), + new KafkaMessage__c( + CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Key__c = '2541865828329', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["2541865828329","10460353203"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), + CRM_Status__c = KafkaMessageService.STATUS_PENDING) + }); + Test.stopTest(); + Person__c[] people = [SELECT + INT_ActorId__c, + INT_GTDistrictNumber__c, + INT_GTMunicipalityNumber__c, + INT_DistrictNumber__c, + INT_MunicipalityNumber__c, + INT_RegionNumber__c + FROM Person__c]; + printLogs(); + Assert.areEqual(2, people.size()); + for (Person__c p : people) { + Assert.areEqual('1337', p.INT_GTMunicipalityNumber__c); + // ... + } + } + /* @IsTest static void setGTFromKommunenummerNoDistrict() { From 22a0883f1d3c0bd15ebfd5ffe58874ffe70dc24b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 8 Mar 2024 16:20:19 +0100 Subject: [PATCH 082/159] fill out the district test --- force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index 37c4ffc0..c83480c3 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -197,7 +197,6 @@ private with sharing class KafkaPdlGtHandlerTest { /** * Tests setting _all_ of the fields, based on district number. - * TODO: check if INT_GTMunicipalityNumber__c should perhaps not be set. * https://pdl-docs.intern.nav.no/ekstern/index.html#geografisk-tilknytning */ @IsTest @@ -229,8 +228,11 @@ private with sharing class KafkaPdlGtHandlerTest { printLogs(); Assert.areEqual(2, people.size()); for (Person__c p : people) { + Assert.areEqual('133769', p.INT_GTDistrictNumber__c); Assert.areEqual('1337', p.INT_GTMunicipalityNumber__c); - // ... + Assert.areEqual('133769', p.INT_DistrictNumber__c); + Assert.areEqual('1337', p.INT_MunicipalityNumber__c); + Assert.areEqual('13', p.INT_RegionNumber__c); } } From a90c40b0510b7d39409489e17125cba3e20e031c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 8 Mar 2024 16:27:34 +0100 Subject: [PATCH 083/159] pass --- force-app/pdl-handler/classes/KafkaPdlGtHandler.cls | 3 +++ 1 file changed, 3 insertions(+) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index 3b6a2325..fe7365db 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -25,6 +25,9 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer private static void setFieldsFromDistrict(Person__c p, PdlGeografiskTilknytning gt) { p.INT_GTDistrictNumber__c = gt.gtBydel; p.INT_GTMunicipalityNumber__c = gt.gtBydel.left(4); + p.INT_DistrictNumber__c = p.INT_GTDistrictNumber__c; + p.INT_MunicipalityNumber__c = p.INT_GTMunicipalityNumber__c; + p.INT_RegionNumber__c = gt.gtBydel.left(2); } /** From c2e4bf6f21365e94e721245aa81e38b07217326a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 11 Mar 2024 12:51:13 +0100 Subject: [PATCH 084/159] also pass municipality test again --- force-app/pdl-handler/classes/KafkaPdlGtHandler.cls | 12 ++++++++++++ .../pdl-handler/classes/KafkaPdlGtHandlerTest.cls | 11 +++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index fe7365db..0684a246 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -22,6 +22,9 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer } } + /** + * District includes all the data we need. + */ private static void setFieldsFromDistrict(Person__c p, PdlGeografiskTilknytning gt) { p.INT_GTDistrictNumber__c = gt.gtBydel; p.INT_GTMunicipalityNumber__c = gt.gtBydel.left(4); @@ -30,6 +33,12 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer p.INT_RegionNumber__c = gt.gtBydel.left(2); } + private static void setFieldsFromMunicipality(Person__c p, PdlGeografiskTilknytning gt) { + p.INT_GTMunicipalityNumber__c = gt.gtKommune; + p.INT_MunicipalityNumber__c = p.INT_GTMunicipalityNumber__c; + p.INT_RegionNumber__c = gt.gtKommune.left(2); + } + /** * Transform and map fields from PDL data structure to Person__c SObject * @param person New Person__c SObject record @@ -45,6 +54,9 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer if (gt.gtType == 'BYDEL') { logger.info('Setting GT from district', null); setFieldsFromDistrict(person, gt); + } else if (gt.gtType == 'KOMMUNE') { + logger.info('Setting GT from municipality', null); + setFieldsFromMunicipality(person, gt); } else { logger.error('Not setting GT, wtf?', null); } diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index c83480c3..0aa712d1 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -185,14 +185,13 @@ private with sharing class KafkaPdlGtHandlerTest { Test.startTest(); handler.processMessages(kafkaMessages); Test.stopTest(); - ps = [SELECT INT_ActorId__c, INT_GTMunicipalityNumber__c FROM Person__c]; + printLogs(); + ps = [SELECT INT_ActorId__c, INT_GTMunicipalityNumber__c, INT_MunicipalityNumber__c, INT_RegionNumber__c FROM Person__c]; Assert.areEqual(1, ps.size()); p = ps[0]; Assert.areEqual('1337', p.INT_GTMunicipalityNumber__c); - //System.assertEquals('030101', p.INT_GTDistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - //System.assertEquals('03', p.INT_RegionNumber__c, 'Expected INT_RegionNumber__c to be set'); - //System.assertEquals('0301', p.INT_MunicipalityNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - //System.assertEquals('030101', p.INT_DistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); + Assert.areEqual('1337', p.INT_MunicipalityNumber__c); + Assert.areEqual('13', p.INT_RegionNumber__c); } /** @@ -217,6 +216,7 @@ private with sharing class KafkaPdlGtHandlerTest { CRM_Status__c = KafkaMessageService.STATUS_PENDING) }); Test.stopTest(); + printLogs(); Person__c[] people = [SELECT INT_ActorId__c, INT_GTDistrictNumber__c, @@ -225,7 +225,6 @@ private with sharing class KafkaPdlGtHandlerTest { INT_MunicipalityNumber__c, INT_RegionNumber__c FROM Person__c]; - printLogs(); Assert.areEqual(2, people.size()); for (Person__c p : people) { Assert.areEqual('133769', p.INT_GTDistrictNumber__c); From fffe2abd3493358a4ef43d34d4fbf6460b225d64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 11 Mar 2024 17:50:05 +0100 Subject: [PATCH 085/159] write failing test for keeping address info --- .../classes/KafkaPdlGtHandlerTest.cls | 68 +++++++++++++++++-- .../classes/KafkaPdlPersondokumentHandler.cls | 21 +++--- 2 files changed, 76 insertions(+), 13 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index 0aa712d1..44d2827d 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -6,10 +6,31 @@ @IsTest private with sharing class KafkaPdlGtHandlerTest { - static void printLogs() { + /** + * Useful information for debugging + */ + static void printLogsAndFails() { for (Application_Log__c l : [SELECT Category__c, Log_Level__c, Log_Message__c from Application_Log__c]) { System.debug('log entry: ' + l.Category__c + ' ' + l.Log_Level__c + ': ' + l.Log_Message__c); } + for (KafkaMessage__c m : [SELECT CRM_Status__c, CRM_Topic__c, CRM_Key__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE CRM_Status__c!=:KafkaMessageService.STATUS_PROCESSED]) { + System.debug(String.format( + 'unprocessed ({0}) message on {1}:\nKey: {2}\nError: {3}', + new List{ + m.CRM_Status__c, + m.CRM_Topic__c, + m.CRM_Key__c, + m.CRM_ErrorMessage__c})); + } + } + + /** + * Sends kafka messages. like KafkaMessageAsyncJob but without the async + */ + private static void handleMessages() { + new KafkaMessageService( + [SELECT Id, CreatedDate, CRM_Topic__c, CRM_Key__c, CRM_Value__c FROM KafkaMessage__c] + ).handleMessages(); } /** @@ -41,7 +62,7 @@ private with sharing class KafkaPdlGtHandlerTest { createPersonDocumentMessage(aktorId, kp) }; KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); - handler.processMessages(messages); + handler.processMessages(messages); // don't bother inserting the message } /** @@ -185,7 +206,7 @@ private with sharing class KafkaPdlGtHandlerTest { Test.startTest(); handler.processMessages(kafkaMessages); Test.stopTest(); - printLogs(); + printLogsAndFails(); ps = [SELECT INT_ActorId__c, INT_GTMunicipalityNumber__c, INT_MunicipalityNumber__c, INT_RegionNumber__c FROM Person__c]; Assert.areEqual(1, ps.size()); p = ps[0]; @@ -216,7 +237,7 @@ private with sharing class KafkaPdlGtHandlerTest { CRM_Status__c = KafkaMessageService.STATUS_PENDING) }); Test.stopTest(); - printLogs(); + printLogsAndFails(); Person__c[] people = [SELECT INT_ActorId__c, INT_GTDistrictNumber__c, @@ -235,6 +256,45 @@ private with sharing class KafkaPdlGtHandlerTest { } } + /** + * Tests that updating the person document does not clear the address + * information fetched from the geographical affiliation, which should have + * a higher priority. + */ + @IsTest + static void setPersonDocAfterGt() { + Person__c[] people; + String sandvika; + // Basic person + createAndInsertBaseKafkaPerson('4398046511104', '68719476736'); + Test.startTest(); + // Set GT + insert new KafkaMessage__c( + CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Key__c = '4398046511104', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), + CRM_Status__c = KafkaMessageService.STATUS_PENDING); + handleMessages(); + people = [SELECT INT_MunicipalityNumber__c from Person__c]; + Assert.areEqual(1, people.size()); + sandvika = people[0].INT_MunicipalityNumber__c; + Assert.areEqual('1337', sandvika); + System.debug(Database.query('SELECT ' + String.join(Schema.Person__c.SObjectType.getDescribe().fields.getMap().keySet(), ',') + ' FROM Person__c')); + // Minimal update to person that shouldn't affect address + insert new KafkaMessage__c( + CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Key__c = '4398046511104', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"hentPerson":{"adressebeskyttelse":[],"bostedsadresse":[],"deltBosted":[],"doedfoedtBarn":[],"doedsfall":[],"foedsel":[],"folkeregisteridentifikator":[],"folkeregisterpersonstatus":[],"forelderBarnRelasjon":[],"foreldreansvar":[],"fullmakt":[],"identitetsgrunnlag":[],"innflyttingTilNorge":[],"kjoenn":[],"kontaktadresse":[],"kontaktinformasjonForDoedsbo":[],"navn":[{"etternavn":"FORTSATTSEN"}],"opphold":[],"oppholdsadresse":[],"sikkerhetstiltak":[],"sivilstand":[],"statsborgerskap":[],"telefonnummer":[],"tilrettelagtKommunikasjon":[],"utenlandskIdentifikasjonsnummer":[],"utflyttingFraNorge":[],"vergemaalEllerFremtidsfullmakt":[]},"hentIdenter":{"identer":[{"ident":"68719476736","historisk":false,"gruppe":"FOLKEREGISTERIDENT","metadata":null,"folkeregistermetadata":null},{"ident":"4398046511104","historisk":false,"gruppe":"AKTORID","metadata":null,"folkeregistermetadata":null}]}}')), + CRM_Status__c = KafkaMessageService.STATUS_PENDING); + handleMessages(); + printLogsAndFails(); + people = [SELECT INT_MunicipalityNumber__c from Person__c]; + Assert.areEqual(1, people.size()); + sandvika = people[0].INT_MunicipalityNumber__c; + Assert.areEqual('1337', sandvika); + System.debug(Database.query('SELECT ' + String.join(Schema.Person__c.SObjectType.getDescribe().fields.getMap().keySet(), ',') + ' FROM Person__c')); + } + /* @IsTest static void setGTFromKommunenummerNoDistrict() { diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index b8a01aac..a433e9c5 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -58,21 +58,19 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess String errorMsg = e.getTypeName() + ': ' + e.getMessage() + ' (' + e.getLineNumber() + ')'; setMessageError(errorMsg, msg, KafkaMessageService.STATUS_ERROR); logger.error( - 'Error creating Person__c from PDL Kafka message. ' + - '\n ' + + 'Caught PdlIdentException when attempting to create Person__c:\n' + e.getMessage() + '\n Kafka key reference: ' + msg.CRM_Key__c, - null, - CRM_ApplicationDomain.domain.NKS + null ); } catch (Exception e) { String errorMsg = e.getTypeName() + ': ' + e.getMessage() + ' (' + e.getLineNumber() + ')'; setMessageError(errorMsg, msg); if (msg.CRM_Status__c == KafkaMessageService.STATUS_ERROR) { logger.error( - 'Error creating Person__c from PDL Kafka message. ' + - '\n Kafka key reference: ' + + 'Caught unknown exception when attempting to create Person__c.\n' + + 'Kafka key reference: ' + msg.CRM_Key__c, null, CRM_ApplicationDomain.domain.NKS @@ -129,7 +127,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess /** * Validates that the Kafka Message is not older than the last PDL Update on * the Person. - * If a new person is a tombstone, do not import it. + * If a new person is a tombstone, mark it not to be imported. * Tombstones are not explicitly named in the message key, but are described * by an empty message value. * @param messages Set of Kafka Messages in scope @@ -298,8 +296,12 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess private Person__c mapFieldValues(Person__c person, KafkaPerson3 kafkaPerson) { KafkaPerson3.HentIdenter hentIdenter = kafkaPerson.hentIdenter; PDL_HentPerson hentPerson = kafkaPerson.hentPerson; + + // Required fields setIdents(person, kafkaPerson); setName(person, hentIdenter); + + // No longer required fields setDateOfBirth(person, hentPerson); // Navn @@ -714,11 +716,12 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * - _not_ FNR from HentIdenter, for whatever reason * - FNR from HentPerson, overrides the above * - DNR from HentPerson - * Throws error unless both HentIdenter and HentPerson exist. + * Throws error unless ident lists from both HentIdenter and HentPerson + * exist; they can be empty, but not null. */ private static void setIdents(Person__c person, KafkaPerson3 kp) { PDL_IdentInformasjon[] identer = kp.hentIdenter.identer; - PDL_Folkeregisteridentifikator[] fregIdenter = kp.hentPerson.folkeregisteridentifikator; + PDL_Folkeregisteridentifikator[] fregIdenter = kp.hentPerson?.folkeregisteridentifikator; if (identer != null && identer.isEmpty() == false) { person.INT_NPID__c = Pdl_IdentUtility.getIdentsFromList(identer).npid; } else { From 07a220fcfd05c64cf4ae94b849270f9a77e4882f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Thu, 14 Mar 2024 23:34:55 +0100 Subject: [PATCH 086/159] pass test by fetching gt for existing actors --- .../classes/KafkaPdlGtHandlerTest.cls | 6 +- .../classes/KafkaPdlPersondokumentHandler.cls | 84 +++++++++++++++---- 2 files changed, 74 insertions(+), 16 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index 44d2827d..2176821b 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -190,6 +190,8 @@ private with sharing class KafkaPdlGtHandlerTest { static void setGTFromKommunenummer() { createAndInsertBaseKafkaPerson('4398046511104', '68719476736'); Person__c[] ps = [SELECT INT_ActorId__c, INT_GTMunicipalityNumber__c FROM Person__c]; + printLogsAndFails(); + System.debug('all people in db: ' + JSON.serializePretty(Database.query('SELECT ' + String.join(Schema.Person__c.SObjectType.getDescribe().fields.getMap().keySet(), ',') + ' FROM Person__c'))); Assert.areEqual(1, ps.size()); Person__c p = ps[0]; Assert.isNull(p.INT_GTMunicipalityNumber__c); @@ -279,7 +281,7 @@ private with sharing class KafkaPdlGtHandlerTest { Assert.areEqual(1, people.size()); sandvika = people[0].INT_MunicipalityNumber__c; Assert.areEqual('1337', sandvika); - System.debug(Database.query('SELECT ' + String.join(Schema.Person__c.SObjectType.getDescribe().fields.getMap().keySet(), ',') + ' FROM Person__c')); + System.debug('all people in db: ' + JSON.serializePretty(Database.query('SELECT ' + String.join(Schema.Person__c.SObjectType.getDescribe().fields.getMap().keySet(), ',') + ' FROM Person__c'))); // Minimal update to person that shouldn't affect address insert new KafkaMessage__c( CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', @@ -288,11 +290,11 @@ private with sharing class KafkaPdlGtHandlerTest { CRM_Status__c = KafkaMessageService.STATUS_PENDING); handleMessages(); printLogsAndFails(); + System.debug('all people in db: ' + JSON.serializePretty(Database.query('SELECT ' + String.join(Schema.Person__c.SObjectType.getDescribe().fields.getMap().keySet(), ',') + ' FROM Person__c'))); people = [SELECT INT_MunicipalityNumber__c from Person__c]; Assert.areEqual(1, people.size()); sandvika = people[0].INT_MunicipalityNumber__c; Assert.areEqual('1337', sandvika); - System.debug(Database.query('SELECT ' + String.join(Schema.Person__c.SObjectType.getDescribe().fields.getMap().keySet(), ',') + ' FROM Person__c')); } /* diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index a433e9c5..35a98d82 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -31,6 +31,26 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess private LoggerUtility logger; + /** + * Gets existing INT_GT... fields from the database. + */ + private void fetchGeografiskTilknytning( + Map gtFromActorId, List messages + ) { + List idList = new List(); + for (KafkaMessage__c msg : messages) { + idList.add(msg.CRM_Key__c); + } + Person__c[] people = [ + SELECT INT_ActorId__c, INT_GTDistrictNumber__c, INT_GTMunicipalityNumber__c + FROM Person__c + WHERE INT_ActorId__c in :idList + ]; + for (Person__c p : people) { + gtFromActorId.put(p.INT_ActorId__c, p); + } + } + /** * Process messages. Warn or error according to some criteria on which I'm * not entirely clear yet. Any explicitly raised PdlIdentException seems to @@ -39,6 +59,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess public void processMessages(List messages) { logger = new LoggerUtility('PDL'); Map personMap = new Map(); + Map gtMap = new Map(); existingActors = new Set(); Map messageMap = new Map(); @@ -46,11 +67,14 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess //If we have a tombstone without a person in Salesforce, set it to processed. checkLastUpdatedAndTombStones(messages); + // If we have INT_GT... fields already saved, we would like to keep them. + fetchGeografiskTilknytning(gtMap, messages); + // Errors are caught and saved on each KafkaMessage record for (KafkaMessage__c msg : messages) { if (msg.CRM_Status__c == KafkaMessageService.STATUS_PENDING) { try { - Person__c person = createPersonRecords(msg); + Person__c person = createPersonRecord(msg, gtMap.get(msg.CRM_Key__c)); personMap.put(person.INT_ActorId__c, person); messageMap.put(person.INT_ActorId__c, msg); msg.CRM_Status__c = KafkaMessageService.STATUS_PROCESSED; @@ -240,7 +264,9 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * @param message integration record inserted by the integration user * @return Initialized Person Account ready for DML */ - private Person__c createPersonRecords(KafkaMessage__c message) { + private Person__c createPersonRecord( + KafkaMessage__c message, Person__c gtPerson + ) { Person__c person = new Person__c( INT_IsHasTombstone__c = String.isBlank(message.CRM_Value__c), INT_ActorId__c = message.CRM_Key__c, @@ -266,7 +292,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } //validateListSizes(kafkaPerson); - person = mapFieldValues(person, kafkaPerson); + person = mapFieldValues(person, kafkaPerson, gtPerson); return person; } @@ -293,7 +319,9 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * @param kafkaPerson deserialized object representing a PersonDokument * @return Person Account with initialized fields */ - private Person__c mapFieldValues(Person__c person, KafkaPerson3 kafkaPerson) { + private Person__c mapFieldValues( + Person__c person, KafkaPerson3 kafkaPerson, Person__c gtPerson + ) { KafkaPerson3.HentIdenter hentIdenter = kafkaPerson.hentIdenter; PDL_HentPerson hentPerson = kafkaPerson.hentPerson; @@ -334,9 +362,8 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess // adresse setAddress(person, kafkaPerson.hentPerson); - /* - setMunicipalityAndGT(person, kafkaPerson); - */ + // this _needs_ to be after adresse, so put them in the same method pls + setMunicipalityAndOrDistrict(person, gtPerson); // statsborgerskap person.INT_Citizenships__c = createCitizenshipString(hentPerson.statsborgerskap); @@ -417,7 +444,9 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * Sets the address. + * Sets the address, in the priority seen within the method. Also sets + * municipality and district numbers, as long as they would not override + * these numbers from GT, which has a higher priority. */ @TestVisible private void setAddressFortroligOrUgradert(Person__c person, PDL_HentPerson hentPerson) { @@ -491,6 +520,32 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } } + /** + * Sets municipality and/or district number. + * Prioritize GT, only use the hentPerson address if there is no better + * source. + * @param p person to be inserted + * @param gtPerson existing person, may be null + */ + private void setMunicipalityAndOrDistrict(Person__c p, Person__c gtPerson) { + if (gtPerson?.INT_GTDistrictNumber__c != null) { + logger.info('setting municipality and district from gt district', null); + p.INT_GTDistrictNumber__c = gtPerson.INT_GTDistrictNumber__c; + p.INT_DistrictNumber__c = p.INT_GTDistrictNumber__c; + p.INT_MunicipalityNumber__c = p.INT_GTDistrictNumber__c.left(4); + } + else if (gtPerson?.INT_GTMunicipalityNumber__c != null) { + logger.info('setting municipality from gt municipality', null); + p.INT_GTMunicipalityNumber__c = gtPerson.INT_GTMunicipalityNumber__c; + p.INT_MunicipalityNumber__c = p.INT_GTMunicipalityNumber__c; + } + else { + logger.info('setting municipality and district from hentPerson', null); + p.INT_DistrictNumber__c = p.INT_AddressDistrictNumber__c; + p.INT_MunicipalityNumber__c = p.INT_AddressMunicipalityNumber__c; + } + } + @TestVisible private void setMunicipalityAndGT(Person__c person, KafkaPerson2 kafkaPerson) { // Set GT Municipality and District numbers @@ -791,10 +846,10 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * Sets empty value for all Person__c fields. Ensures that e.g. - * INT_DateOfDeath__c is removed when it has previously been erroneously set - * — and then corrected by creating a person document that does not contain - * a date of death. + * Sets empty value for all Person__c fields set by this handler. Ensures + * that e.g. INT_DateOfDeath__c is removed when it has previously been + * erroneously set — and then corrected by creating a person document that + * does not contain a date of death. * @param person record to modify * TODO: ensure we haven't missed anything. */ @@ -813,8 +868,9 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess 'INT_FamilyRelations__c', 'INT_FirstName__c', 'INT_fnr__c', - 'INT_GTDistrictNumber__c', - 'INT_GTMunicipalityNumber__c', + // No longer set by this handler: + //'INT_GTDistrictNumber__c', + //'INT_GTMunicipalityNumber__c', 'INT_GuardianshipOrFuturePowerOfAttorney__c', 'INT_LastName__c', 'INT_LegalStatus__c', From 3f073f14e215cb18c931dd023d9c745432ec9bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 15 Mar 2024 15:33:50 +0100 Subject: [PATCH 087/159] add failing test for nulling obsolete dist/mpty --- .../pdl-handler/classes/KafkaPdlGtHandler.cls | 1 + .../classes/KafkaPdlGtHandlerTest.cls | 62 +++++++++++++++---- 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index 0684a246..2a740c36 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -95,6 +95,7 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer } List urList = Database.upsert(persons, Person__c.INT_ActorId__c, false); // TODO check for errors, set status to error if so + System.debug(JSON.serializepretty(urList)); logger.publish(); } diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index 2176821b..ae89cf21 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -9,13 +9,14 @@ private with sharing class KafkaPdlGtHandlerTest { /** * Useful information for debugging */ - static void printLogsAndFails() { + private static void printLogsAndMessages() { for (Application_Log__c l : [SELECT Category__c, Log_Level__c, Log_Message__c from Application_Log__c]) { System.debug('log entry: ' + l.Category__c + ' ' + l.Log_Level__c + ': ' + l.Log_Message__c); } - for (KafkaMessage__c m : [SELECT CRM_Status__c, CRM_Topic__c, CRM_Key__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE CRM_Status__c!=:KafkaMessageService.STATUS_PROCESSED]) { + for (KafkaMessage__c m : [SELECT CRM_Status__c, CRM_Topic__c, CRM_Key__c, CRM_ErrorMessage__c FROM KafkaMessage__c]) { // WHERE CRM_Status__c!=:KafkaMessageService.STATUS_PROCESSED]) { System.debug(String.format( - 'unprocessed ({0}) message on {1}:\nKey: {2}\nError: {3}', + //'unprocessed ({0}) message on {1}:\nKey: {2}\nError: {3}', + '{0} message on {1}:\nKey: {2}\nError: {3}', new List{ m.CRM_Status__c, m.CRM_Topic__c, @@ -24,12 +25,20 @@ private with sharing class KafkaPdlGtHandlerTest { } } + /** + * Occasionally useful information for debugging. + * (Obviously never run this in a big environment.) + */ + private static void printPeople() { + System.debug('all people in db: ' + JSON.serializePretty(Database.query('SELECT ' + String.join(Schema.Person__c.SObjectType.getDescribe().fields.getMap().keySet(), ',') + ' FROM Person__c'))); + } + /** * Sends kafka messages. like KafkaMessageAsyncJob but without the async */ private static void handleMessages() { new KafkaMessageService( - [SELECT Id, CreatedDate, CRM_Topic__c, CRM_Key__c, CRM_Value__c FROM KafkaMessage__c] + [SELECT Id, CreatedDate, CRM_Topic__c, CRM_Key__c, CRM_Value__c FROM KafkaMessage__c WHERE CRM_Status__c = :KafkaMessageService.STATUS_PENDING] ).handleMessages(); } @@ -190,8 +199,8 @@ private with sharing class KafkaPdlGtHandlerTest { static void setGTFromKommunenummer() { createAndInsertBaseKafkaPerson('4398046511104', '68719476736'); Person__c[] ps = [SELECT INT_ActorId__c, INT_GTMunicipalityNumber__c FROM Person__c]; - printLogsAndFails(); - System.debug('all people in db: ' + JSON.serializePretty(Database.query('SELECT ' + String.join(Schema.Person__c.SObjectType.getDescribe().fields.getMap().keySet(), ',') + ' FROM Person__c'))); + printLogsAndMessages(); + printPeople(); Assert.areEqual(1, ps.size()); Person__c p = ps[0]; Assert.isNull(p.INT_GTMunicipalityNumber__c); @@ -208,7 +217,7 @@ private with sharing class KafkaPdlGtHandlerTest { Test.startTest(); handler.processMessages(kafkaMessages); Test.stopTest(); - printLogsAndFails(); + printLogsAndMessages(); ps = [SELECT INT_ActorId__c, INT_GTMunicipalityNumber__c, INT_MunicipalityNumber__c, INT_RegionNumber__c FROM Person__c]; Assert.areEqual(1, ps.size()); p = ps[0]; @@ -239,7 +248,7 @@ private with sharing class KafkaPdlGtHandlerTest { CRM_Status__c = KafkaMessageService.STATUS_PENDING) }); Test.stopTest(); - printLogsAndFails(); + printLogsAndMessages(); Person__c[] people = [SELECT INT_ActorId__c, INT_GTDistrictNumber__c, @@ -281,7 +290,6 @@ private with sharing class KafkaPdlGtHandlerTest { Assert.areEqual(1, people.size()); sandvika = people[0].INT_MunicipalityNumber__c; Assert.areEqual('1337', sandvika); - System.debug('all people in db: ' + JSON.serializePretty(Database.query('SELECT ' + String.join(Schema.Person__c.SObjectType.getDescribe().fields.getMap().keySet(), ',') + ' FROM Person__c'))); // Minimal update to person that shouldn't affect address insert new KafkaMessage__c( CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', @@ -289,14 +297,46 @@ private with sharing class KafkaPdlGtHandlerTest { CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"hentPerson":{"adressebeskyttelse":[],"bostedsadresse":[],"deltBosted":[],"doedfoedtBarn":[],"doedsfall":[],"foedsel":[],"folkeregisteridentifikator":[],"folkeregisterpersonstatus":[],"forelderBarnRelasjon":[],"foreldreansvar":[],"fullmakt":[],"identitetsgrunnlag":[],"innflyttingTilNorge":[],"kjoenn":[],"kontaktadresse":[],"kontaktinformasjonForDoedsbo":[],"navn":[{"etternavn":"FORTSATTSEN"}],"opphold":[],"oppholdsadresse":[],"sikkerhetstiltak":[],"sivilstand":[],"statsborgerskap":[],"telefonnummer":[],"tilrettelagtKommunikasjon":[],"utenlandskIdentifikasjonsnummer":[],"utflyttingFraNorge":[],"vergemaalEllerFremtidsfullmakt":[]},"hentIdenter":{"identer":[{"ident":"68719476736","historisk":false,"gruppe":"FOLKEREGISTERIDENT","metadata":null,"folkeregistermetadata":null},{"ident":"4398046511104","historisk":false,"gruppe":"AKTORID","metadata":null,"folkeregistermetadata":null}]}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING); handleMessages(); - printLogsAndFails(); - System.debug('all people in db: ' + JSON.serializePretty(Database.query('SELECT ' + String.join(Schema.Person__c.SObjectType.getDescribe().fields.getMap().keySet(), ',') + ' FROM Person__c'))); + printLogsAndMessages(); + printPeople(); people = [SELECT INT_MunicipalityNumber__c from Person__c]; Assert.areEqual(1, people.size()); sandvika = people[0].INT_MunicipalityNumber__c; Assert.areEqual('1337', sandvika); } + /** + * Tests that nothing remains of the old GT when inserting a new GT with + * lower precision. + */ + @IsTest + static void setMunicipalityAfterDistrict() { + Person__c guy; + // Give our guy the highest precision (district) + insert new KafkaMessage__c( + CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Key__c = '4398046511104', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), + CRM_Status__c = KafkaMessageService.STATUS_PENDING); + handleMessages(); + guy = [SELECT INT_GTDistrictNumber__c, INT_DistrictNumber__c, INT_MunicipalityNumber__c from Person__c][0]; + Assert.areEqual('1337', guy.INT_MunicipalityNumber__c); + Assert.areEqual('133769', guy.INT_GTDistrictNumber__c); + Assert.areEqual('133769', guy.INT_DistrictNumber__c); + insert new KafkaMessage__c( + CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Key__c = '4398046511104', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"KOMMUNE","gtKommune":"2024","gtBydel":null,"gtLand":null,"regel":"666"}}')), + CRM_Status__c = KafkaMessageService.STATUS_PENDING); + Test.startTest(); + AsyncRequestSchedulable.enqueueAsyncJobs(); // This enqueues the job. + Test.stopTest(); // This runs the job. + guy = [SELECT INT_GTDistrictNumber__c, INT_DistrictNumber__c, INT_MunicipalityNumber__c from Person__c][0]; + Assert.areEqual('2024', guy.INT_MunicipalityNumber__c); + Assert.isNull(guy.INT_GTDistrictNumber__c); + Assert.isNull(guy.INT_DistrictNumber__c); + } + /* @IsTest static void setGTFromKommunenummerNoDistrict() { From 6022cba62cf879ce8e4b7ec943356914a2f39ca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 20 Mar 2024 01:54:02 +0100 Subject: [PATCH 088/159] pass test --- .../pdl-handler/classes/KafkaPdlGtHandler.cls | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index 2a740c36..fcd1d2ff 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -22,6 +22,17 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer } } + /** + * Nulls what may have been set before. + */ + private static void nullOutFields(Person__c p) { + p.INT_GTDistrictNumber__c = null; + p.INT_GTMunicipalityNumber__c = null; + p.INT_DistrictNumber__c = null; + p.INT_MunicipalityNumber__c = null; + p.INT_RegionNumber__c = null; + } + /** * District includes all the data we need. */ @@ -33,6 +44,9 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer p.INT_RegionNumber__c = gt.gtBydel.left(2); } + /** + * Municipality does not set the district. + */ private static void setFieldsFromMunicipality(Person__c p, PdlGeografiskTilknytning gt) { p.INT_GTMunicipalityNumber__c = gt.gtKommune; p.INT_MunicipalityNumber__c = p.INT_GTMunicipalityNumber__c; @@ -50,6 +64,7 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer for(String s : kafkaPerson.identer) { assignIdent(person, s); } + nullOutFields(person); PdlGeografiskTilknytning gt = kafkaPerson.geografiskTilknytning; if (gt.gtType == 'BYDEL') { logger.info('Setting GT from district', null); From b25a8afe9b5d89fe6a7781137083c19f89c1de84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 20 Mar 2024 01:54:38 +0100 Subject: [PATCH 089/159] add test for nulling obsolete municipality --- .../pdl-handler/classes/KafkaPdlGtHandler.cls | 5 +++ .../classes/KafkaPdlGtHandlerTest.cls | 33 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index fcd1d2ff..180abbd3 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -72,6 +72,11 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer } else if (gt.gtType == 'KOMMUNE') { logger.info('Setting GT from municipality', null); setFieldsFromMunicipality(person, gt); + } else if (gt.gtType == 'UDEFINERT') { + logger.info('Not setting GT from UDEFINERT', null); + } else if (gt.gtType == 'UTLAND') { + logger.info('Setting GT from abroad', null); + // TODO } else { logger.error('Not setting GT, wtf?', null); } diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index ae89cf21..3012a8b6 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -331,12 +331,45 @@ private with sharing class KafkaPdlGtHandlerTest { Test.startTest(); AsyncRequestSchedulable.enqueueAsyncJobs(); // This enqueues the job. Test.stopTest(); // This runs the job. + printLogsAndMessages(); guy = [SELECT INT_GTDistrictNumber__c, INT_DistrictNumber__c, INT_MunicipalityNumber__c from Person__c][0]; Assert.areEqual('2024', guy.INT_MunicipalityNumber__c); Assert.isNull(guy.INT_GTDistrictNumber__c); Assert.isNull(guy.INT_DistrictNumber__c); } + /** + * Tests that nothing remains of the old GT when inserting UDEFINERT. + */ + @IsTest + static void setUndefinedAfterDistrict() { + Person__c guy; + // Give our guy the highest precision (district) + insert new KafkaMessage__c( + CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Key__c = '4398046511104', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), + CRM_Status__c = KafkaMessageService.STATUS_PENDING); + handleMessages(); + guy = [SELECT INT_GTDistrictNumber__c, INT_DistrictNumber__c, INT_MunicipalityNumber__c from Person__c][0]; + Assert.areEqual('1337', guy.INT_MunicipalityNumber__c); + insert new KafkaMessage__c( + CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Key__c = '4398046511104', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"UDEFINERT","gtKommune":null,"gtBydel":null,"gtLand":null,"regel":"666"}}')), + CRM_Status__c = KafkaMessageService.STATUS_PENDING); + Test.startTest(); + AsyncRequestSchedulable.enqueueAsyncJobs(); // This enqueues the job. + Test.stopTest(); // This runs the job. + printLogsAndMessages(); + guy = [SELECT INT_GTDistrictNumber__c, INT_DistrictNumber__c, INT_GTMunicipalityNumber__c, INT_MunicipalityNumber__c, INT_RegionNumber__c from Person__c][0]; + Assert.isNull(guy.INT_GTDistrictNumber__c); + Assert.isNull(guy.INT_DistrictNumber__c); + Assert.isNull(guy.INT_GTMunicipalityNumber__c); + Assert.isNull(guy.INT_MunicipalityNumber__c); + Assert.isNull(guy.INT_RegionNumber__c); + } + /* @IsTest static void setGTFromKommunenummerNoDistrict() { From cfa76f3b1724f6d93db2c6b7f171ad9f7f8e9b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 20 Mar 2024 02:02:40 +0100 Subject: [PATCH 090/159] remove obsolete tests --- .../classes/KafkaPdlGtHandlerTest.cls | 50 ------------------- 1 file changed, 50 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index 3012a8b6..11815b05 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -369,54 +369,4 @@ private with sharing class KafkaPdlGtHandlerTest { Assert.isNull(guy.INT_MunicipalityNumber__c); Assert.isNull(guy.INT_RegionNumber__c); } - - /* - @IsTest - static void setGTFromKommunenummerNoDistrict() { - Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); - KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); - kafkaPerson.kommunenummerFraGt = '0301'; - - Test.startTest(); - KafkaPDLHandler2 handler = new KafkaPDLHandler2(); - handler.setMunicipalityAndGT(person, kafkaPerson); - Test.stopTest(); - - System.assertEquals( - '0301', - person.INT_GTMunicipalityNumber__c, - 'Expected INT_GTMunicipalityNumber__c to be set' - ); - System.assertEquals(null, person.INT_GTDistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - System.assertEquals('03', person.INT_RegionNumber__c, 'Expected INT_RegionNumber__c to be set'); - System.assertEquals('0301', person.INT_MunicipalityNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - System.assertEquals(null, person.INT_DistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - } - - @IsTest - static void setGTFromKommunenummerFromAddressOnly() { - Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); - KafkaPerson2 kafkaPerson = createBaseKafkaPerson('11223344556'); - kafkaPerson.bostedsadresse.vegadresse.add(new KafkaPerson2.Vegadresse()); - kafkaPerson.bostedsadresse.vegadresse[0].adressenavn = 'Testveien'; - kafkaPerson.bostedsadresse.vegadresse[0].adressenavn = '1'; - kafkaPerson.bostedsadresse.vegadresse[0].adressenavn = 'A'; - kafkaPerson.bostedsadresse.vegadresse[0].postnummer = '0001'; - kafkaPerson.bostedsadresse.vegadresse[0].kommunenummer = '4321'; - kafkaPerson.bostedsadresse.vegadresse[0].bydelsnummer = '030110'; - kafkaPerson.bostedsadresse.vegadresse[0].koordinater = 'x=354424, y=6862099, z=0'; - - Test.startTest(); - KafkaPDLHandler2 handler = new KafkaPDLHandler2(); - handler.setAddress(person, kafkaPerson); - handler.setMunicipalityAndGT(person, kafkaPerson); - Test.stopTest(); - - System.assertEquals(null, person.INT_GTMunicipalityNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - System.assertEquals(null, person.INT_GTDistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - System.assertEquals(null, person.INT_RegionNumber__c, 'Expected INT_RegionNumber__c to be set'); - System.assertEquals('4321', person.INT_MunicipalityNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - System.assertEquals('030110', person.INT_DistrictNumber__c, 'Expected INT_GTMunicipalityNumber__c to be set'); - } - */ } From 4899d3ff83a30f664194d8fbcd6bba0d3a202d00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 20 Mar 2024 02:13:30 +0100 Subject: [PATCH 091/159] update setPersonDocAfterGt to include new address --- force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index 11815b05..197e9aac 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -294,7 +294,7 @@ private with sharing class KafkaPdlGtHandlerTest { insert new KafkaMessage__c( CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', CRM_Key__c = '4398046511104', - CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"hentPerson":{"adressebeskyttelse":[],"bostedsadresse":[],"deltBosted":[],"doedfoedtBarn":[],"doedsfall":[],"foedsel":[],"folkeregisteridentifikator":[],"folkeregisterpersonstatus":[],"forelderBarnRelasjon":[],"foreldreansvar":[],"fullmakt":[],"identitetsgrunnlag":[],"innflyttingTilNorge":[],"kjoenn":[],"kontaktadresse":[],"kontaktinformasjonForDoedsbo":[],"navn":[{"etternavn":"FORTSATTSEN"}],"opphold":[],"oppholdsadresse":[],"sikkerhetstiltak":[],"sivilstand":[],"statsborgerskap":[],"telefonnummer":[],"tilrettelagtKommunikasjon":[],"utenlandskIdentifikasjonsnummer":[],"utflyttingFraNorge":[],"vergemaalEllerFremtidsfullmakt":[]},"hentIdenter":{"identer":[{"ident":"68719476736","historisk":false,"gruppe":"FOLKEREGISTERIDENT","metadata":null,"folkeregistermetadata":null},{"ident":"4398046511104","historisk":false,"gruppe":"AKTORID","metadata":null,"folkeregistermetadata":null}]}}')), + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"hentPerson":{"adressebeskyttelse":[],"bostedsadresse":[{"angittFlyttedato":"1972-09-26","gyldigFraOgMed":"1972-09-26T00:00:00","gyldigTilOgMed":null,"coAdressenavn":null,"vegadresse":{"matrikkelId":330462890,"husnummer":"54","husbokstav":null,"bruksenhetsnummer":null,"adressenavn":"Tromøy kirkevei","kommunenummer":"4203","tilleggsnavn":null,"postnummer":"4818","bydelsnummer":null,"koordinater":{"x":489639.3,"y":6478898.8,"z":null}},"matrikkeladresse":null,"ukjentBosted":null,"utenlandskAdresse":null,"folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:39.83","gyldighetstidspunkt":"1972-09-26T00:00:00","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"582d32a7-f923-467a-9cd6-17976f6727d2","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:39.83","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"deltBosted":[],"doedfoedtBarn":[],"doedsfall":[],"foedsel":[],"folkeregisteridentifikator":[],"folkeregisterpersonstatus":[],"forelderBarnRelasjon":[],"foreldreansvar":[],"fullmakt":[],"identitetsgrunnlag":[],"innflyttingTilNorge":[],"kjoenn":[],"kontaktadresse":[],"kontaktinformasjonForDoedsbo":[],"navn":[{"etternavn":"FORTSATTSEN"}],"opphold":[],"oppholdsadresse":[],"sikkerhetstiltak":[],"sivilstand":[],"statsborgerskap":[],"telefonnummer":[],"tilrettelagtKommunikasjon":[],"utenlandskIdentifikasjonsnummer":[],"utflyttingFraNorge":[],"vergemaalEllerFremtidsfullmakt":[]},"hentIdenter":{"identer":[{"ident":"68719476736","historisk":false,"gruppe":"FOLKEREGISTERIDENT","metadata":null,"folkeregistermetadata":null},{"ident":"4398046511104","historisk":false,"gruppe":"AKTORID","metadata":null,"folkeregistermetadata":null}]}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING); handleMessages(); printLogsAndMessages(); From ce9eefe4d51ac42bc5e7c46a7f430e27051a7e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 20 Mar 2024 02:26:10 +0100 Subject: [PATCH 092/159] set correct OwnerId when processing manually --- force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 2 -- 1 file changed, 2 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 35a98d82..a4238325 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -422,12 +422,10 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess ? null : JSON.serialize(hentPerson.vergemaalEllerFremtidsfullmakt); - /* // Ensure that a System User is set as Owner if even if message processing is manually retried by an administrator user if (KafkaIntegrationCustomSetting.integrationUserId != null) { person.OwnerId = KafkaIntegrationCustomSetting.integrationUserId; } - */ return person; } From 513849d4874fa61e2631d7bcb47342568451b032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 20 Mar 2024 10:19:10 +0100 Subject: [PATCH 093/159] instantiate logger in constructor, minor refactor --- .../classes/KafkaPdlPersondokumentHandler.cls | 11 ++++------- .../classes/KafkaPdlPersondokumentHandlerTest.cls | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index a4238325..cc19a1f5 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -29,7 +29,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess private Set existingActors; - private LoggerUtility logger; + private LoggerUtility logger = new LoggerUtility('PDL'); /** * Gets existing INT_GT... fields from the database. @@ -57,7 +57,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * raise an error. */ public void processMessages(List messages) { - logger = new LoggerUtility('PDL'); Map personMap = new Map(); Map gtMap = new Map(); existingActors = new Set(); @@ -360,10 +359,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess person.INT_SecurityMeasures__c = JSON.serialize(kafkaPerson.hentPerson.sikkerhetstiltak); // adresse - setAddress(person, kafkaPerson.hentPerson); - - // this _needs_ to be after adresse, so put them in the same method pls - setMunicipalityAndOrDistrict(person, gtPerson); + setAddress(person, kafkaPerson.hentPerson, gtPerson); // statsborgerskap person.INT_Citizenships__c = createCitizenshipString(hentPerson.statsborgerskap); @@ -512,9 +508,10 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * to the person object. Seems dangerous. */ @TestVisible - private void setAddress(Person__c person, PDL_HentPerson hentPerson) { + private void setAddress(Person__c person, PDL_HentPerson hentPerson, Person__c gtPerson) { if (ADR_BESKYTTELSES_GRADERING.get(person.INT_Confidential__c) <= 2) { setAddressFortroligOrUgradert(person, hentPerson); + setMunicipalityAndOrDistrict(person, gtPerson); } } diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index ef2345d7..1211eb81 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1318,7 +1318,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { kafkaPerson.hentPerson.bostedsadresse.add(bo); Test.startTest(); KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); - handler.setAddress(person, kafkaPerson.hentPerson); + handler.setAddress(person, kafkaPerson.hentPerson, null); Test.stopTest(); Assert.areEqual( 'Testveien 1 A', @@ -1412,7 +1412,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { kafkaPerson.hentPerson.oppholdsadresse.add(opphold); Test.startTest(); KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); - handler.setAddress(person, kafkaPerson.hentPerson); + handler.setAddress(person, kafkaPerson.hentPerson, null); Test.stopTest(); Assert.isNull(person.INT_ResidentialAddress__c); Assert.isNull(person.INT_ResidentialZipCode__c); From debc52b3f250e4ab8089bf56f622a3af1b9cf840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Thu, 21 Mar 2024 00:47:26 +0100 Subject: [PATCH 094/159] minor --- force-app/pdl-handler/classes/KafkaPdlGtHandler.cls | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index 180abbd3..e49bfada 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -75,10 +75,10 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer } else if (gt.gtType == 'UDEFINERT') { logger.info('Not setting GT from UDEFINERT', null); } else if (gt.gtType == 'UTLAND') { - logger.info('Setting GT from abroad', null); + logger.info('GT from abroad, doing nothing.', null); // TODO } else { - logger.error('Not setting GT, wtf?', null); + logger.error('Not setting GT, unknown gtType.', null); } //person.INT_GTMunicipalityNumber__c = gt.gtKommune; return person; From 7346154bdad04dcc08da0f64c105a72f4de4ebd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 22 Mar 2024 15:38:29 +0100 Subject: [PATCH 095/159] whitespace --- .../classes/KafkaPdlPersondokumentHandler.cls | 29 +++---------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index cc19a1f5..32ae0fb5 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -61,14 +61,12 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess Map gtMap = new Map(); existingActors = new Set(); Map messageMap = new Map(); - - //If we have a message where the created date is older than last updated, set it to error so that we can investigate it. - //If we have a tombstone without a person in Salesforce, set it to processed. + // If we have a message where the created date is older than last + // updated, set it to error so that we can investigate it. If we have a + // tombstone without a person in Salesforce, set it to processed. checkLastUpdatedAndTombStones(messages); - // If we have INT_GT... fields already saved, we would like to keep them. fetchGeografiskTilknytning(gtMap, messages); - // Errors are caught and saved on each KafkaMessage record for (KafkaMessage__c msg : messages) { if (msg.CRM_Status__c == KafkaMessageService.STATUS_PENDING) { @@ -166,7 +164,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess List updatedList = new List(); Map updatedMap = new Map(); Set split = new Set(); - for (KafkaMessage__c msg : messages) { String actorId = msg.CRM_Key__c; Boolean isTombstone = msg.CRM_Value__c == null; @@ -206,7 +203,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } } existingActors = updatedMap.keySet(); - for (Integer i = 0; i < messages.size(); i++) { if (split.contains(idList[i])) { //when a few person records with same actor id exists @@ -244,7 +240,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess private Map getPersonLastUpdatedMap(List actorIds) { Map lastUpdatedMap = new Map(); - for (Person__c p : [ SELECT INT_ActorId__c, INT_LastUpdatedFromPDL__c FROM Person__c @@ -252,7 +247,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess ]) { lastUpdatedMap.put(p.INT_ActorId__c, p.INT_LastUpdatedFromPDL__c); } - return lastUpdatedMap; } @@ -271,15 +265,12 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess INT_ActorId__c = message.CRM_Key__c, INT_LastUpdatedFromPDL__c = message.createdDate ); - // If tombstone and no payload, clear data for person except idents. if (true == person.INT_IsHasTombstone__c && String.isBlank(message.CRM_Value__c)) { emptyTombstonePerson(person); return person; } - emptyPersonFieldValues(person); - String decodedValue = KafkaMessageUtils.base64ULSafeDecode(message.CRM_Value__c).toString(); // Fail loudly when deserialization goes wrong. KafkaPerson3 kafkaPerson; @@ -289,10 +280,8 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess throw new PdlIdentException('Failed to parse kafka person: ' + e.getTypeName() + ': ' + e.getMessage() + ' (' + e.getLineNumber() + ')'); } - //validateListSizes(kafkaPerson); person = mapFieldValues(person, kafkaPerson, gtPerson); - return person; } @@ -466,7 +455,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess person.INT_AddressDistrictNumber__c = bo.matrikkeladresse.bydelsnummer; person.INT_Coordinates__c = formatCoordinates(bo.matrikkeladresse.koordinater); } - // oppholdsadresser // assumption: vegadresse has first pri, then utenlandskAdresse, then ukjentbosted PDL_Oppholdsadresse opphold = hentPerson.oppholdsadresse.size() > 0 ? hentPerson.oppholdsadresse[0] : null; @@ -552,7 +540,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess person.INT_RegionNumber__c = kafkaPerson.bydelsnummerFraGt.left(2); person.INT_GTDistrictNumber__c = kafkaPerson.bydelsnummerFraGt; } - // Set Municipality and District from GT if available, otherwise from Bostedsaddresse if (person.INT_GTMunicipalityNumber__c != null) { person.INT_MunicipalityNumber__c = person.INT_GTMunicipalityNumber__c; @@ -654,21 +641,16 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * Validate list sizes and if errors are found, throw error to store on the relevant Kafka Message * @param kafkaPerson Kafka person to validate */ - // prettier-ignore private void validateListSizes(KafkaPerson2 kafkaPerson) { List objectsFailingValidation = new List(); - - if(kafkaPerson.identer == null) { if (kafkaPerson.folkeregisterId.size() == 0) { throw new pdlMissingEntryException('No folkeregisterId found'); } if (kafkaPerson.folkeregisterpersonstatus.size() == 0) { throw new pdlMissingEntryException('No folkeregisterpersonstatus found'); } } else { if (kafkaPerson.identer.size() == 0) { throw new pdlMissingEntryException('No idents found'); } } - if (kafkaPerson.navn.size() == 0) { throw new pdlMissingEntryException('No name found'); } if (kafkaPerson.navn[0].etternavn == null) {throw new pdlMissingEntryException('No etternavn found'); } - // Check for list sizes greater than one if (kafkaPerson.bostedsadresse.vegadresse.size() > 1) { objectsFailingValidation.add('bostedsadresse.vegadresse'); } if (kafkaPerson.bostedsadresse.matrikkeladresse.size() > 1) { objectsFailingValidation.add('bostedsadresse.matrikkeladresse'); } @@ -678,7 +660,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess if (kafkaPerson.oppholdsadresse.matrikkeladresse.size() > 1) { objectsFailingValidation.add('oppholdsadresse.matrikkeladresse'); } if (kafkaPerson.oppholdsadresse.utenlandskAdresse.size() > 1) { objectsFailingValidation.add('oppholdsadresse.utenlandskAdresse'); } if (kafkaPerson.oppholdsadresse.ukjentBosted.size() > 1) { objectsFailingValidation.add('oppholdsadresse.ukjentBosted'); } - if (objectsFailingValidation.size() > 0) { throw new pdlListContainsTooManyEntriesException( 'Multiple objects received for ' + @@ -686,6 +667,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess ); } } + /** * Create map from ISO country codes to English Country Label * @param commonCodeList List Common_Code__c records @@ -732,7 +714,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess if (ISO_MAP.containsKey(isoCode)) { return ISO_MAP.get(isoCode); } - if (String.isNotBlank(isoCode)) { logger.error( 'Error getting country from ISO Code.' + @@ -897,7 +878,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess for (String intField : intFields) { person.put(intField, null); } - //Set field value to false for (String boolField : new List{ 'INT_IsDeceased__c' }) { person.put(boolField, false); @@ -963,7 +943,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess for (String intField : intFields) { person.put(intField, null); } - //Set field value to false for ( String boolField : new List{ 'INT_IsDeceased__c', 'INT_IsNavEmployee__c', 'INT_KRR_Reservation__c' } From 42307b4b5e4f51ed145515464a2cf7051ec0aee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 2 Apr 2024 17:43:32 +0200 Subject: [PATCH 096/159] validate some sizes on freg-ident and -status (all tests pass) --- .../classes/KafkaPdlPersondokumentHandler.cls | 46 ++++++++++++++----- .../KafkaPdlPersondokumentHandlerTest.cls | 9 ++++ 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 32ae0fb5..22396a2a 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -280,7 +280,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess throw new PdlIdentException('Failed to parse kafka person: ' + e.getTypeName() + ': ' + e.getMessage() + ' (' + e.getLineNumber() + ')'); } - //validateListSizes(kafkaPerson); + validateListSizes(kafkaPerson); // assume there's a good reason to do this person = mapFieldValues(person, kafkaPerson, gtPerson); return person; } @@ -427,14 +427,14 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * Sets the address, in the priority seen within the method. Also sets - * municipality and district numbers, as long as they would not override - * these numbers from GT, which has a higher priority. + * Sets the address according to the priority seen within the method. Also + * sets municipality and district numbers, as long as they would not + * override these numbers from GT, which has a higher priority. */ @TestVisible private void setAddressFortroligOrUgradert(Person__c person, PDL_HentPerson hentPerson) { // bostedsadresser - // assumption: vegadresse has first pri, then ukjentbosted + // assumption: vegadresse has first pri, then ukjentbosted... PDL_Bostedsadresse bo = hentPerson.bostedsadresse.size() > 0 ? hentPerson.bostedsadresse[0] : null; if (bo?.vegadresse != null) { person.INT_ResidentialAddress__c = addressCreator( @@ -455,6 +455,23 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess person.INT_AddressDistrictNumber__c = bo.matrikkeladresse.bydelsnummer; person.INT_Coordinates__c = formatCoordinates(bo.matrikkeladresse.koordinater); } + // ...PDL skal til enhver tid kun ha en gyldig bostedsadresse per + // person. Hver gang en ny bostedsadresse blir registrert så vil den + // forrige bli historisk. Norsk bostedsadresse vil alltid ha Freg som + // master. Utenlandsk bostedsadresse vil alltid ha PDL som master. + // Personer som er registrert som døde skal ikke kunne ha en + // bostedsadresse. + // ... + // At PDL har en utenlandsk bostedsadresse betyr at NAV har mottatt en + // adresse av den typen fra en utenlandsk myndighet. Det betyr ikke at + // det er gjort en vurdering i NAV av hvor en person skal regnes som + // bosatt. + // ... + // Personer med en gyldig bostedsadresse i Norge, kan ikke bli + // registrert med en utenlandsk bostedsadresse. Da må den norske + // adressen først opphøres i Folkeregisteret. + // ...TODO: pull in the foreign address, probably + // oppholdsadresser // assumption: vegadresse has first pri, then utenlandskAdresse, then ukjentbosted PDL_Oppholdsadresse opphold = hentPerson.oppholdsadresse.size() > 0 ? hentPerson.oppholdsadresse[0] : null; @@ -641,16 +658,20 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * Validate list sizes and if errors are found, throw error to store on the relevant Kafka Message * @param kafkaPerson Kafka person to validate */ - private void validateListSizes(KafkaPerson2 kafkaPerson) { + private void validateListSizes(KafkaPerson3 kafkaPerson) { + PDL_HentPerson hp = kafkaPerson.hentPerson; + KafkaPerson3.HentIdenter hentIdenter = kafkaPerson.hentIdenter; + List objectsFailingValidation = new List(); - if(kafkaPerson.identer == null) { - if (kafkaPerson.folkeregisterId.size() == 0) { throw new pdlMissingEntryException('No folkeregisterId found'); } - if (kafkaPerson.folkeregisterpersonstatus.size() == 0) { throw new pdlMissingEntryException('No folkeregisterpersonstatus found'); } + if(hentIdenter.identer == null) { + if (hp.folkeregisteridentifikator.size() == 0) { throw new PdlMissingEntryException('No folkeregisteridentifikator found'); } + if (hp.folkeregisterpersonstatus.size() == 0) { throw new PdlMissingEntryException('No folkeregisterpersonstatus found'); } } else { - if (kafkaPerson.identer.size() == 0) { throw new pdlMissingEntryException('No idents found'); } + if (hentIdenter.identer.size() == 0) { throw new PdlMissingEntryException('No idents found'); } } - if (kafkaPerson.navn.size() == 0) { throw new pdlMissingEntryException('No name found'); } - if (kafkaPerson.navn[0].etternavn == null) {throw new pdlMissingEntryException('No etternavn found'); } + /* + if (kafkaPerson.navn.size() == 0) { throw new PdlMissingEntryException('No name found'); } + if (kafkaPerson.navn[0].etternavn == null) {throw new PdlMissingEntryException('No etternavn found'); } // Check for list sizes greater than one if (kafkaPerson.bostedsadresse.vegadresse.size() > 1) { objectsFailingValidation.add('bostedsadresse.vegadresse'); } if (kafkaPerson.bostedsadresse.matrikkeladresse.size() > 1) { objectsFailingValidation.add('bostedsadresse.matrikkeladresse'); } @@ -666,6 +687,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess String.join(objectsFailingValidation, ',') ); } + */ } /** diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 1211eb81..44d45c1f 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1,6 +1,14 @@ @IsTest private with sharing class KafkaPdlPersondokumentHandlerTest { + /** + * Occasionally useful information for debugging. + * (Obviously never run this in a big environment.) + */ + private static void printPeople() { + System.debug('all people in db: ' + JSON.serializePretty(Database.query('SELECT ' + String.join(Schema.Person__c.SObjectType.getDescribe().fields.getMap().keySet(), ',') + ' FROM Person__c'))); + } + /** * Creates data we would otherwise fetch; common codes, and so on. */ @@ -1186,6 +1194,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message.Id LIMIT 1] ); Person__c person = getPersonAccountByActorIdent().get('1122334455666'); + printPeople(); Assert.areEqual('1122334455666', person.INT_actorId__c, 'Expected AKTØR ID to be set'); Assert.areEqual('12345678901', person.INT_fnr__c, 'Expected FNR to be set'); From 9129e6d5c262865e649930505bc8fa1c6408cbd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 3 Apr 2024 16:13:06 +0200 Subject: [PATCH 097/159] validate some more --- .../classes/KafkaPdlPersondokumentHandler.cls | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 22396a2a..f94510a7 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -656,6 +656,8 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess /** * Validate list sizes and if errors are found, throw error to store on the relevant Kafka Message + * I'm guessing this ensures that the proxy has reduced lists of historical + * addresses etc down to the non-historical one (at most) * @param kafkaPerson Kafka person to validate */ private void validateListSizes(KafkaPerson3 kafkaPerson) { @@ -669,25 +671,18 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } else { if (hentIdenter.identer.size() == 0) { throw new PdlMissingEntryException('No idents found'); } } - /* - if (kafkaPerson.navn.size() == 0) { throw new PdlMissingEntryException('No name found'); } - if (kafkaPerson.navn[0].etternavn == null) {throw new PdlMissingEntryException('No etternavn found'); } + if (hp.navn.size() == 0) { throw new PdlMissingEntryException('No name found'); } + if (hp.navn[0].etternavn == null) {throw new PdlMissingEntryException('No etternavn found'); } // Check for list sizes greater than one - if (kafkaPerson.bostedsadresse.vegadresse.size() > 1) { objectsFailingValidation.add('bostedsadresse.vegadresse'); } - if (kafkaPerson.bostedsadresse.matrikkeladresse.size() > 1) { objectsFailingValidation.add('bostedsadresse.matrikkeladresse'); } - if (kafkaPerson.bostedsadresse.utenlandskAdresse.size() > 1) { objectsFailingValidation.add('bostedsadresse.utenlandskAdresse'); } - if (kafkaPerson.bostedsadresse.ukjentBosted.size() > 1) { objectsFailingValidation.add('bostedsadresse.ukjentBosted'); } - if (kafkaPerson.oppholdsadresse.vegadresse.size() > 1) { objectsFailingValidation.add('oppholdsadresse.vegadresse'); } - if (kafkaPerson.oppholdsadresse.matrikkeladresse.size() > 1) { objectsFailingValidation.add('oppholdsadresse.matrikkeladresse'); } - if (kafkaPerson.oppholdsadresse.utenlandskAdresse.size() > 1) { objectsFailingValidation.add('oppholdsadresse.utenlandskAdresse'); } - if (kafkaPerson.oppholdsadresse.ukjentBosted.size() > 1) { objectsFailingValidation.add('oppholdsadresse.ukjentBosted'); } + // TODO: consider reducing in here rather than in proxy + if (hp.bostedsadresse.size() > 1) { objectsFailingValidation.add('bostedsadresse'); } + if (hp.oppholdsadresse.size() > 1) { objectsFailingValidation.add('oppholdsadresse'); } if (objectsFailingValidation.size() > 0) { throw new pdlListContainsTooManyEntriesException( 'Multiple objects received for ' + String.join(objectsFailingValidation, ',') ); } - */ } /** From 37b03eef086b45eee85235e5421023ab5f147f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Thu, 4 Apr 2024 00:31:21 +0200 Subject: [PATCH 098/159] delete prints of massive information --- .../classes/KafkaPdlGtHandlerTest.cls | 35 ------------------- .../KafkaPdlPersondokumentHandlerTest.cls | 9 ----- 2 files changed, 44 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index 197e9aac..a18b4b7a 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -6,33 +6,6 @@ @IsTest private with sharing class KafkaPdlGtHandlerTest { - /** - * Useful information for debugging - */ - private static void printLogsAndMessages() { - for (Application_Log__c l : [SELECT Category__c, Log_Level__c, Log_Message__c from Application_Log__c]) { - System.debug('log entry: ' + l.Category__c + ' ' + l.Log_Level__c + ': ' + l.Log_Message__c); - } - for (KafkaMessage__c m : [SELECT CRM_Status__c, CRM_Topic__c, CRM_Key__c, CRM_ErrorMessage__c FROM KafkaMessage__c]) { // WHERE CRM_Status__c!=:KafkaMessageService.STATUS_PROCESSED]) { - System.debug(String.format( - //'unprocessed ({0}) message on {1}:\nKey: {2}\nError: {3}', - '{0} message on {1}:\nKey: {2}\nError: {3}', - new List{ - m.CRM_Status__c, - m.CRM_Topic__c, - m.CRM_Key__c, - m.CRM_ErrorMessage__c})); - } - } - - /** - * Occasionally useful information for debugging. - * (Obviously never run this in a big environment.) - */ - private static void printPeople() { - System.debug('all people in db: ' + JSON.serializePretty(Database.query('SELECT ' + String.join(Schema.Person__c.SObjectType.getDescribe().fields.getMap().keySet(), ',') + ' FROM Person__c'))); - } - /** * Sends kafka messages. like KafkaMessageAsyncJob but without the async */ @@ -199,8 +172,6 @@ private with sharing class KafkaPdlGtHandlerTest { static void setGTFromKommunenummer() { createAndInsertBaseKafkaPerson('4398046511104', '68719476736'); Person__c[] ps = [SELECT INT_ActorId__c, INT_GTMunicipalityNumber__c FROM Person__c]; - printLogsAndMessages(); - printPeople(); Assert.areEqual(1, ps.size()); Person__c p = ps[0]; Assert.isNull(p.INT_GTMunicipalityNumber__c); @@ -217,7 +188,6 @@ private with sharing class KafkaPdlGtHandlerTest { Test.startTest(); handler.processMessages(kafkaMessages); Test.stopTest(); - printLogsAndMessages(); ps = [SELECT INT_ActorId__c, INT_GTMunicipalityNumber__c, INT_MunicipalityNumber__c, INT_RegionNumber__c FROM Person__c]; Assert.areEqual(1, ps.size()); p = ps[0]; @@ -248,7 +218,6 @@ private with sharing class KafkaPdlGtHandlerTest { CRM_Status__c = KafkaMessageService.STATUS_PENDING) }); Test.stopTest(); - printLogsAndMessages(); Person__c[] people = [SELECT INT_ActorId__c, INT_GTDistrictNumber__c, @@ -297,8 +266,6 @@ private with sharing class KafkaPdlGtHandlerTest { CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"hentPerson":{"adressebeskyttelse":[],"bostedsadresse":[{"angittFlyttedato":"1972-09-26","gyldigFraOgMed":"1972-09-26T00:00:00","gyldigTilOgMed":null,"coAdressenavn":null,"vegadresse":{"matrikkelId":330462890,"husnummer":"54","husbokstav":null,"bruksenhetsnummer":null,"adressenavn":"Tromøy kirkevei","kommunenummer":"4203","tilleggsnavn":null,"postnummer":"4818","bydelsnummer":null,"koordinater":{"x":489639.3,"y":6478898.8,"z":null}},"matrikkeladresse":null,"ukjentBosted":null,"utenlandskAdresse":null,"folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:39.83","gyldighetstidspunkt":"1972-09-26T00:00:00","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"582d32a7-f923-467a-9cd6-17976f6727d2","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:39.83","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"deltBosted":[],"doedfoedtBarn":[],"doedsfall":[],"foedsel":[],"folkeregisteridentifikator":[],"folkeregisterpersonstatus":[],"forelderBarnRelasjon":[],"foreldreansvar":[],"fullmakt":[],"identitetsgrunnlag":[],"innflyttingTilNorge":[],"kjoenn":[],"kontaktadresse":[],"kontaktinformasjonForDoedsbo":[],"navn":[{"etternavn":"FORTSATTSEN"}],"opphold":[],"oppholdsadresse":[],"sikkerhetstiltak":[],"sivilstand":[],"statsborgerskap":[],"telefonnummer":[],"tilrettelagtKommunikasjon":[],"utenlandskIdentifikasjonsnummer":[],"utflyttingFraNorge":[],"vergemaalEllerFremtidsfullmakt":[]},"hentIdenter":{"identer":[{"ident":"68719476736","historisk":false,"gruppe":"FOLKEREGISTERIDENT","metadata":null,"folkeregistermetadata":null},{"ident":"4398046511104","historisk":false,"gruppe":"AKTORID","metadata":null,"folkeregistermetadata":null}]}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING); handleMessages(); - printLogsAndMessages(); - printPeople(); people = [SELECT INT_MunicipalityNumber__c from Person__c]; Assert.areEqual(1, people.size()); sandvika = people[0].INT_MunicipalityNumber__c; @@ -331,7 +298,6 @@ private with sharing class KafkaPdlGtHandlerTest { Test.startTest(); AsyncRequestSchedulable.enqueueAsyncJobs(); // This enqueues the job. Test.stopTest(); // This runs the job. - printLogsAndMessages(); guy = [SELECT INT_GTDistrictNumber__c, INT_DistrictNumber__c, INT_MunicipalityNumber__c from Person__c][0]; Assert.areEqual('2024', guy.INT_MunicipalityNumber__c); Assert.isNull(guy.INT_GTDistrictNumber__c); @@ -361,7 +327,6 @@ private with sharing class KafkaPdlGtHandlerTest { Test.startTest(); AsyncRequestSchedulable.enqueueAsyncJobs(); // This enqueues the job. Test.stopTest(); // This runs the job. - printLogsAndMessages(); guy = [SELECT INT_GTDistrictNumber__c, INT_DistrictNumber__c, INT_GTMunicipalityNumber__c, INT_MunicipalityNumber__c, INT_RegionNumber__c from Person__c][0]; Assert.isNull(guy.INT_GTDistrictNumber__c); Assert.isNull(guy.INT_DistrictNumber__c); diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 44d45c1f..1211eb81 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1,14 +1,6 @@ @IsTest private with sharing class KafkaPdlPersondokumentHandlerTest { - /** - * Occasionally useful information for debugging. - * (Obviously never run this in a big environment.) - */ - private static void printPeople() { - System.debug('all people in db: ' + JSON.serializePretty(Database.query('SELECT ' + String.join(Schema.Person__c.SObjectType.getDescribe().fields.getMap().keySet(), ',') + ' FROM Person__c'))); - } - /** * Creates data we would otherwise fetch; common codes, and so on. */ @@ -1194,7 +1186,6 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { [SELECT Id, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c WHERE Id = :message.Id LIMIT 1] ); Person__c person = getPersonAccountByActorIdent().get('1122334455666'); - printPeople(); Assert.areEqual('1122334455666', person.INT_actorId__c, 'Expected AKTØR ID to be set'); Assert.areEqual('12345678901', person.INT_fnr__c, 'Expected FNR to be set'); From 2ddfe7f9ebd962d919185b638b8b5a8756701cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 5 Apr 2024 12:11:32 +0200 Subject: [PATCH 099/159] touch up README --- README.md | 81 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index b84481f3..2689594e 100755 --- a/README.md +++ b/README.md @@ -1,44 +1,69 @@ # crm-platform-integration -This package contains the `KafkaMessage__c` sObject and related Apex logic in order to receive JSON payloads representing -changes from the Kafka CDC pipeline. A trigger on the `KafkaMessage__c` sObject will create enqueue asynchronous processing -request through the asynchronous processing framework that is part of the crm-platform-base package. +This package contains the `KafkaMessage__c` sObject and related Apex logic in +order to receive JSON payloads representing changes from the Kafka CDC pipeline. +A trigger on the `KafkaMessage__c` sObject will create enqueue asynchronous +processing request through the asynchronous processing framework that is part of +the crm-platform-base package. ## Custom Metadata Bindings -The framework depends on two custom metadata objects in order to dynamically instruct the application how to handle the message payload. +The framework depends on two custom metadata objects in order to dynamically +instruct the application how to handle the message payload. -### `AsyncRequestHandlerBinding_mdt` +### `AsyncRequestHandlerBinding__mdt` -Binding between the asynchronous processing request (`AsyncRequest__c`) type created by this package and the `KafkaMessageAsyncJob` class -in order to instruct the asynchronous processing framework to call the `KafkaMessageAsyncJob` class in order to handle -requests originating from this package. +Binding between the asynchronous processing request (`AsyncRequest__c`) type +created by this package and the `KafkaMessageAsyncJob` class in order to +instruct the asynchronous processing framework to call the +`KafkaMessageAsyncJob` class in order to handle requests originating from this +package. -### KafkaMessageHandlerBinding_mdt +### `KafkaMessageHandlerBinding__mdt` -Binding between the `KafkaMessage__c.Topic__c` field and an Apex handler class for a given Topic in order to instruct the -application on how to handle a message payload related to a specific Kafka topic. +Binding between the `KafkaMessage__c.Topic__c` field and an Apex handler class +for a given Topic in order to instruct the application on how to handle a +message payload related to a specific Kafka topic. ## Execution Flow -1. An external application inserts a record or batch or records into the KafkaMessage\_\_c sObject -2. A trigger on the KafkaMessage__c object insert one record into the AsyncRequest__c object for each batch of up to 200 - KafkaMessage\_\_c records created in a single transaction, representing a a request for asynchronous processing of the new - messages. -3. When the asynchronous processing framework processes the request, the custom metadata binding `AsyncRequestHandlerBinding_mdt` - instructs the application to handle the request using the `KafkaMessageAsyncJob` Apex class. - If no `AsyncRequestHandlerBinding_mdt` record is found corresponding to the "Kafka Message" AsyncRequestType__c value, - the `AsyncRequest__c` record is updated with an error. -4. The `KafkaMessageAsyncJob` queries for the relevant KafkaMessage__c records by the Ids stored in the async processing - request and queries the `KafkaMessageHandlerBinding_mdt` custom metadata object for registered bindings between `KafkaMessage__c.Topic__c` - values and corresponding Apex classes to handle payloads corresponding to Topic__c values. - If no `KafkaMessageHandlerBinding_mdt` record is found corresponding to the `Topic__c` value, the relevant - `KafkaMessage__c` record is updated with an error. The message kan then be retried after the error has been addressed. -5. The Apex class registered by the `KafkaMessageHandlerBinding_mdt` binding executes the business logic corresponding to the - `Topic__c` value. - If an execption occurs, the relevant`KafkaMessage__c` record is updated with an error. The message kan then be retried - after the error has been addressed. +1. An external application inserts a record or batch or records into the + `KafkaMessage__c` sObject +2. A trigger on the `KafkaMessage__c` object insert one record into the + `AsyncRequest__c` object for each batch of up to 200 `KafkaMessage__c` + records created in a single transaction, representing a request for + asynchronous processing of the new messages. +3. When the asynchronous processing framework processes the request, the custom + metadata binding `AsyncRequestHandlerBinding__mdt` instructs the application + to handle the request using the `KafkaMessageAsyncJob` Apex class. - If no + `AsyncRequestHandlerBinding__mdt` record is found corresponding to the "Kafka + Message" `AsyncRequestType__c` value, the `AsyncRequest__c` record is updated + with an error. +4. The `KafkaMessageAsyncJob` queries for the relevant `KafkaMessage__c` records + by the Ids stored in the async processing request and queries the + `KafkaMessageHandlerBinding__mdt` custom metadata object for registered + bindings between `KafkaMessage__c.Topic__c` values and corresponding Apex + classes to handle payloads corresponding to `Topic__c` values. - If no + `KafkaMessageHandlerBinding__mdt` record is found corresponding to the + `Topic__c` value, the relevant `KafkaMessage__c` record is updated with an + error. The message can then be retried after the error has been addressed. +5. The Apex class registered by the `KafkaMessageHandlerBinding__mdt` binding + executes the business logic corresponding to the `Topic__c` value. - If an + exception occurs, the relevant`KafkaMessage__c` record is updated with an + error. The message can then be retried after the error has been addressed. ## Synchronous kafka message handling -To process incoming kafka messages in a synchronous context the following pattern should be followed: -1. Definition of a separate platform event with the exact data model as i.e. defined [here](https://github.com/navikt/crm-platform-oppgave/tree/master/force-app/main/default/objects/Kafka_Oppgave_Event__e). +To process incoming kafka messages in a synchronous context the following +pattern should be followed: +1. Definition of a separate platform event with the exact data model as i.e. + defined + [here](https://github.com/navikt/crm-platform-oppgave/tree/master/force-app/main/default/objects/Kafka_Oppgave_Event__e). 2. Create a trigger and separate trigger handler to process the incoming events. -3. The processing itself should be implemented using the IKafkaMessageConsumer interface such that error handling can be performed easily storing failed events as KafkaMessage__c records. An example of this can be veiwed [here](https://github.com/navikt/crm-platform-oppgave/blob/master/force-app/main/default/classes/kafka/CRM_KafkaOppgaveEventHandler.cls) where *doEventTransform* performs the transformation from the custom event to the KafkaMessage__c model and the failed events are stored as KafkaMessage__c records in an error status. +3. The processing itself should be implemented using the IKafkaMessageConsumer + interface such that error handling can be performed easily storing failed + events as `KafkaMessage__c` records. An example of this can be viewed + [here](https://github.com/navikt/crm-platform-oppgave/blob/master/force-app/main/default/classes/kafka/CRM_KafkaOppgaveEventHandler.cls) + where *doEventTransform* performs the transformation from the custom event to + the `KafkaMessage__c` model and the failed events are stored as + `KafkaMessage__c` records in an error status. From 8269fc6256cc217e23ea162c8e23f07d8803dd9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 9 Apr 2024 16:51:40 +0200 Subject: [PATCH 100/159] clarify some comments / variable names --- .../classes/KafkaPdlPersondokumentHandler.cls | 42 ++++++++++--------- .../KafkaPdlPersondokumentHandlerTest.cls | 10 ++--- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index f94510a7..74b314b5 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -52,28 +52,29 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * Process messages. Warn or error according to some criteria on which I'm - * not entirely clear yet. Any explicitly raised PdlIdentException seems to - * raise an error. + * Process messages. Warn or error (i.e. set CRM_Status__c on the + * KafkaMessage__c) according to some criteria on which I'm not entirely + * clear yet: + * - PdlIdentException seems to raise an error. */ public void processMessages(List messages) { - Map personMap = new Map(); - Map gtMap = new Map(); + Map personFromActorId = new Map(); + Map gtFromActorId = new Map(); existingActors = new Set(); - Map messageMap = new Map(); + Map messageFromActorId = new Map(); // If we have a message where the created date is older than last // updated, set it to error so that we can investigate it. If we have a // tombstone without a person in Salesforce, set it to processed. checkLastUpdatedAndTombStones(messages); // If we have INT_GT... fields already saved, we would like to keep them. - fetchGeografiskTilknytning(gtMap, messages); + fetchGeografiskTilknytning(gtFromActorId, messages); // Errors are caught and saved on each KafkaMessage record for (KafkaMessage__c msg : messages) { if (msg.CRM_Status__c == KafkaMessageService.STATUS_PENDING) { try { - Person__c person = createPersonRecord(msg, gtMap.get(msg.CRM_Key__c)); - personMap.put(person.INT_ActorId__c, person); - messageMap.put(person.INT_ActorId__c, msg); + Person__c person = createPersonRecord(msg, gtFromActorId.get(msg.CRM_Key__c)); + personFromActorId.put(person.INT_ActorId__c, person); + messageFromActorId.put(person.INT_ActorId__c, msg); msg.CRM_Status__c = KafkaMessageService.STATUS_PROCESSED; } catch (PdlIdentException e) { String errorMsg = e.getTypeName() + ': ' + e.getMessage() + ' (' + e.getLineNumber() + ')'; @@ -110,9 +111,9 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } List personList = new List(); List messageList = new List(); - for (String actorId : personMap.keySet()) { - personList.add(personMap.get(actorId)); - messageList.add(messageMap.get(actorId)); + for (String actorId : personFromActorId.keySet()) { + personList.add(personFromActorId.get(actorId)); + messageList.add(messageFromActorId.get(actorId)); } // Errors from DML will set all messages to failed. List urList = Database.upsert(personList, Person__c.INT_ActorId__c, false); @@ -315,7 +316,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess // Required fields setIdents(person, kafkaPerson); - setName(person, hentIdenter); + setNameField(person, hentIdenter); // No longer required fields setDateOfBirth(person, hentPerson); @@ -655,9 +656,11 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * Validate list sizes and if errors are found, throw error to store on the relevant Kafka Message - * I'm guessing this ensures that the proxy has reduced lists of historical - * addresses etc down to the non-historical one (at most) + * Validate list sizes and if errors are found, throw exception. + * This will be caught and stored on the relevant Kafka Message as a + * warning, info, error, whatever. + * Previously the proxy would reduce a list down to contain only the + * non-historical one. Now we need to do this ourselves. * @param kafkaPerson Kafka person to validate */ private void validateListSizes(KafkaPerson3 kafkaPerson) { @@ -811,13 +814,14 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * Sets the Name field to a valid identifier. + * Sets the Name field of the sObject to a valid identifier. + * Not to be confused with the first name or last name. * Priority: FOLKEREGISTERIDENT, NPID * See https://confluence.adeo.no/display/PDL/NPID+-+NAVs+personidentifikator * If the list does not include valid idents, throws an exception. */ @TestVisible - private static void setName(Person__c person, KafkaPerson3.HentIdenter hentIdenter) { + private static void setNameField(Person__c person, KafkaPerson3.HentIdenter hentIdenter) { List identer = new List(hentIdenter.identer); String flkId; String npId; diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 1211eb81..8ece819e 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -213,7 +213,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { * Also tests that Name is set to NPID when the FOLKEREGISTERIDENT exists * but is historic. */ - static void setNameTest() { + static void setNameFieldTest() { KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); Integer i = kPerson.hentIdenter.identer.size() - 1; @@ -238,11 +238,11 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { kPerson.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; Person__c person = new Person__c(); System.Test.startTest(); // eh - KafkaPdlPersondokumentHandler.setName(person, kPerson.hentIdenter); + KafkaPdlPersondokumentHandler.setNameField(person, kPerson.hentIdenter); Assert.areEqual('12345678901', person.Name, 'Expected non historisk FOLKEREGISTERIDENT'); person = new Person__c(); kPerson.hentIdenter.identer[fregIndex].historisk = true; - KafkaPdlPersondokumentHandler.setName(person, kPerson.hentIdenter); + KafkaPdlPersondokumentHandler.setNameField(person, kPerson.hentIdenter); System.Test.stopTest(); Assert.areEqual('12345678911', person.Name, 'Expected non historisk NPID'); } @@ -252,7 +252,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { * Tests that person's Name is not set and instead an exception is thrown * when FOLKEREGISTERIDENT and NPID exist but are historic. */ - static void setNameException() { + static void setNameFieldException() { KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); Integer i = kPerson.hentIdenter.identer.size() - 1; @@ -277,7 +277,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Person__c person = new Person__c(); System.Test.startTest(); try { - KafkaPdlPersondokumentHandler.setName(person, kPerson.hentIdenter); + KafkaPdlPersondokumentHandler.setNameField(person, kPerson.hentIdenter); Assert.fail('No exception thrown'); } catch (KafkaPdlPersondokumentHandler.PdlIdentException ex) { System.assert(true); // ಠ_ಠ From d8a4274eac67743c431d25cb1b30e1bf841fefc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Sat, 13 Apr 2024 15:32:43 +0200 Subject: [PATCH 101/159] add failing historical-differentiating test --- .../KafkaPdlPersondokumentHandlerTest.cls | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 8ece819e..5c14da60 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1344,6 +1344,62 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.isNull(person.INT_TemporaryCountryCode__c); } + /** + * Tests that the historical address is not saved but the non-historical one is + */ + @IsTest + static void setNonHistoricalBosted() { + Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); + KafkaPerson3 kafkaPerson = createBaseKafkaPerson('1122334455666'); + PDL_Bostedsadresse bo = new PDL_Bostedsadresse(); + bo.vegadresse = new PDL_Vegadresse(); + bo.vegadresse.adressenavn = 'Gamleveien'; + bo.vegadresse.husnummer = '1'; + bo.vegadresse.husbokstav = 'A'; + bo.vegadresse.postnummer = '0001'; + bo.vegadresse.kommunenummer = '4321'; + bo.vegadresse.bydelsnummer = '030110'; + bo.vegadresse.koordinater = (PDL_Koordinater)System.JSON.deserialize( + '{"x":354424, "y":6862099, "z":0}', PDL_Koordinater.class); + bo.metadata = new PDL_Metadata(); + bo.metadata.historisk = true; + kafkaPerson.hentPerson.bostedsadresse.add(bo); + bo = new PDL_Bostedsadresse(); + bo.vegadresse = new PDL_Vegadresse(); + bo.vegadresse.adressenavn = 'Nyveien'; + bo.vegadresse.husnummer = '2'; + bo.vegadresse.husbokstav = 'B'; + bo.vegadresse.postnummer = '0002'; + bo.vegadresse.kommunenummer = '5432'; + bo.vegadresse.bydelsnummer = '141221'; + bo.vegadresse.koordinater = (PDL_Koordinater)System.JSON.deserialize( + '{"x":354424, "y":6862099, "z":0}', PDL_Koordinater.class); + kafkaPerson.hentPerson.bostedsadresse.add(bo); + Test.startTest(); + KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); + handler.setAddress(person, kafkaPerson.hentPerson, null); + Test.stopTest(); + Assert.areEqual( + 'Nyveien 2 B', + person.INT_ResidentialAddress__c, + 'Expected residential address to be set correctly' + ); + Assert.areEqual('0002', person.INT_ResidentialZipCode__c, 'Expected residential zip code to be set'); + Assert.areEqual( + '5432', + person.INT_AddressMunicipalityNumber__c + ); + Assert.areEqual( + '141221', + person.INT_AddressDistrictNumber__c + ); + Assert.isNull(person.INT_TemporaryAddress__c); + Assert.isNull(person.INT_TemporaryZipCode__c); + Assert.isNull(person.INT_TemporaryMunicipalityNumber__c); + Assert.isNull(person.INT_TemporaryCoordinates__c); + Assert.isNull(person.INT_TemporaryCountryCode__c); + } + /** * Test secondary address, and that setAddress is actually called. */ From 7748be883d2af01fe968f58f52c823886eb99a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 15 Apr 2024 10:21:11 +0200 Subject: [PATCH 102/159] pass test by adding new parent class with metadata allows a single method to reduce entries down to the one that is not historical, rather than requiring one for every single attribute --- .../classes/PdlBostedsadresse.cls | 12 ++++ .../classes/PdlBostedsadresse.cls-meta.xml | 5 ++ .../pdl-apexTypes/classes/PdlHentperson.cls | 65 +++++++++++++++++++ .../classes/PdlHentperson.cls-meta.xml | 5 ++ force-app/pdl-apexTypes/classes/PdlObject.cls | 7 ++ .../classes/PdlObject.cls-meta.xml | 5 ++ .../classes/KafkaPdlGtHandlerTest.cls | 4 +- .../classes/KafkaPdlPersondokumentHandler.cls | 31 +++++++-- .../KafkaPdlPersondokumentHandlerTest.cls | 12 ++-- .../pdl-handler/classes/KafkaPerson3.cls | 2 +- 10 files changed, 132 insertions(+), 16 deletions(-) create mode 100644 force-app/pdl-apexTypes/classes/PdlBostedsadresse.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlBostedsadresse.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlHentperson.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlHentperson.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlObject.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlObject.cls-meta.xml diff --git a/force-app/pdl-apexTypes/classes/PdlBostedsadresse.cls b/force-app/pdl-apexTypes/classes/PdlBostedsadresse.cls new file mode 100644 index 00000000..3ba58ef8 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlBostedsadresse.cls @@ -0,0 +1,12 @@ +public with sharing class PdlBostedsadresse extends PdlObject { + public Date angittFlyttedato{ get;} + public Datetime gyldigFraOgMed{ get;} + public Datetime gyldigTilOgMed{ get;} + public String coAdressenavn{ get;} + @TestVisible + public PDL_Vegadresse vegadresse{ get;} + public PDL_Matrikkeladresse matrikkeladresse{ get;} + public PDL_UtenlandskAdresse utenlandskAdresse{ get;} + public PDL_UkjentBosted ukjentBosted{ get;} + public PDL_Folkeregistermetadata folkeregistermetadata{ get;} +} diff --git a/force-app/pdl-apexTypes/classes/PdlBostedsadresse.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlBostedsadresse.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlBostedsadresse.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlHentperson.cls b/force-app/pdl-apexTypes/classes/PdlHentperson.cls new file mode 100644 index 00000000..86ae03af --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlHentperson.cls @@ -0,0 +1,65 @@ +/** + * Identical to PDL_HentPerson except its attributes inherit metadata + */ +public with sharing class PdlHentperson { + + @TestVisible + public PDL_Adressebeskyttelse[] adressebeskyttelse{ get;} + @TestVisible + public PdlBostedsadresse[] bostedsadresse{ get;} + @TestVisible + public PDL_DeltBosted[] deltBosted{ get;} + @TestVisible + public PDL_DoedfoedtBarn[] doedfoedtBarn{ get;} + @TestVisible + public PDL_Doedsfall[] doedsfall{ get;} + @TestVisible + public PDL_FalskIdentitet falskIdentitet{ get;} + @TestVisible + public PDL_Foedsel[] foedsel{ get;} + @TestVisible + public PDL_Folkeregisteridentifikator[] folkeregisteridentifikator{ get;} + @TestVisible + public PDL_Folkeregisterpersonstatus[] folkeregisterpersonstatus{ get;} + @TestVisible + public PDL_ForelderBarnRelasjon[] forelderBarnRelasjon{ get;} + @TestVisible + public PDL_Foreldreansvar[] foreldreansvar{ get;} + @TestVisible + public PDL_Fullmakt[] fullmakt{ get;} + @TestVisible + public PDL_Identitetsgrunnlag[] identitetsgrunnlag{ get;} + @TestVisible + public PDL_InnflyttingTilNorge[] innflyttingTilNorge{ get;} + @TestVisible + public PDL_Kjoenn[] kjoenn{ get;} + @TestVisible + public PDL_Kontaktadresse[] kontaktadresse{ get;} + @TestVisible + public PDL_KontaktinformasjonForDoedsbo[] kontaktinformasjonForDoedsbo{ get;} + @TestVisible + public PDL_Navn[] navn{ get;} + @TestVisible + public PDL_Opphold[] opphold{ get;} + @TestVisible + public PDL_Oppholdsadresse[] oppholdsadresse{ get;} + @TestVisible + public PDL_Sikkerhetstiltak[] sikkerhetstiltak{ get;} + @TestVisible + public PDL_Sivilstand[] sivilstand{ get;} + @TestVisible + public PDL_Statsborgerskap[] statsborgerskap{ get;} + @TestVisible + public PDL_Telefonnummer[] telefonnummer{ get;} + @TestVisible + public PDL_TilrettelagtKommunikasjon[] tilrettelagtKommunikasjon{ get;} + @TestVisible + public PDL_UtenlandskIdentifikasjonsnummer[] utenlandskIdentifikasjonsnummer{ get;} + @TestVisible + public PDL_UtflyttingFraNorge[] utflyttingFraNorge{ get;} + @TestVisible + public PDL_VergemaalEllerFremtidsfullmakt[] vergemaalEllerFremtidsfullmakt{ get;} + + public PdlHentperson() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlHentperson.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlHentperson.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlHentperson.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlObject.cls b/force-app/pdl-apexTypes/classes/PdlObject.cls new file mode 100644 index 00000000..4883c1e6 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlObject.cls @@ -0,0 +1,7 @@ +/** + * Common elements of all Pdl classes + */ +public virtual class PdlObject { + @TestVisible + public PDL_Metadata metadata{ get;} +} diff --git a/force-app/pdl-apexTypes/classes/PdlObject.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlObject.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlObject.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index a18b4b7a..4c6a343d 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -55,10 +55,10 @@ private with sharing class KafkaPdlGtHandlerTest { KafkaPerson3 kp = new KafkaPerson3(); kp.hentIdenter = new KafkaPerson3.HentIdenter(); kp.hentIdenter.identer = new List(); - kp.hentPerson = new PDL_HentPerson(); + kp.hentPerson = new PdlHentperson(); // just initialise all the lists. kp.hentPerson.adressebeskyttelse = new List(); - kp.hentPerson.bostedsadresse = new List(); + kp.hentPerson.bostedsadresse = new List(); kp.hentPerson.deltBosted = new List(); kp.hentPerson.doedfoedtBarn = new List(); kp.hentPerson.doedsfall = new List(); diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 74b314b5..42713170 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -290,7 +290,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * Set date (or year) of birth. * Takes Date or Integer, sets String. */ - private static void setDateOfBirth(Person__c person, PDL_HentPerson hentPerson) { + private static void setDateOfBirth(Person__c person, PdlHentperson hentPerson) { if (hentPerson.foedsel != null && !hentPerson.foedsel.isEmpty()) { PDL_Foedsel foedsel = hentPerson.foedsel[hentPerson.foedsel.size() - 1]; if (foedsel.foedselsdato != null) { @@ -312,7 +312,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess Person__c person, KafkaPerson3 kafkaPerson, Person__c gtPerson ) { KafkaPerson3.HentIdenter hentIdenter = kafkaPerson.hentIdenter; - PDL_HentPerson hentPerson = kafkaPerson.hentPerson; + PdlHentperson hentPerson = kafkaPerson.hentPerson; // Required fields setIdents(person, kafkaPerson); @@ -427,16 +427,33 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess k.z}); } + /** + * Fetches the non-historical entry out of a list of entries. + * Returns first entry where metadata is + * - null (implicitly active) + * - explicitly not historical + * Occasionally there may be multiple valid entries, e.g. one from FREG, one from PDL. + * Handle that if it becomes necessary. + */ + private PdlObject getActiveOrNone(PdlObject[] pos) { + for(PdlObject po : pos) { + if(!(po.metadata?.historisk ?? false)) { + return po; + } + } + return null; + } + /** * Sets the address according to the priority seen within the method. Also * sets municipality and district numbers, as long as they would not * override these numbers from GT, which has a higher priority. */ @TestVisible - private void setAddressFortroligOrUgradert(Person__c person, PDL_HentPerson hentPerson) { + private void setAddressFortroligOrUgradert(Person__c person, PdlHentperson hentPerson) { // bostedsadresser // assumption: vegadresse has first pri, then ukjentbosted... - PDL_Bostedsadresse bo = hentPerson.bostedsadresse.size() > 0 ? hentPerson.bostedsadresse[0] : null; + PdlBostedsadresse bo = (PdlBostedsadresse)getActiveOrNone(hentPerson.bostedsadresse); if (bo?.vegadresse != null) { person.INT_ResidentialAddress__c = addressCreator( new List{ @@ -514,7 +531,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * to the person object. Seems dangerous. */ @TestVisible - private void setAddress(Person__c person, PDL_HentPerson hentPerson, Person__c gtPerson) { + private void setAddress(Person__c person, PdlHentperson hentPerson, Person__c gtPerson) { if (ADR_BESKYTTELSES_GRADERING.get(person.INT_Confidential__c) <= 2) { setAddressFortroligOrUgradert(person, hentPerson); setMunicipalityAndOrDistrict(person, gtPerson); @@ -664,7 +681,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * @param kafkaPerson Kafka person to validate */ private void validateListSizes(KafkaPerson3 kafkaPerson) { - PDL_HentPerson hp = kafkaPerson.hentPerson; + PdlHentperson hp = kafkaPerson.hentPerson; KafkaPerson3.HentIdenter hentIdenter = kafkaPerson.hentIdenter; List objectsFailingValidation = new List(); @@ -799,7 +816,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * Sets idents. Based on the same function in PDL_HentPerson. + * Sets idents. Based on the same function in KafkaPDLHandler2. */ private static void setFolkeregisterIdents( Person__c person, diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 5c14da60..59dec962 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -29,17 +29,17 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { } /** - * Initializes KafkaPerson3 with PDL_IdentInformasjon and PDL_HentPerson, + * Initializes KafkaPerson3 with PDL_IdentInformasjon and PdlHentperson, * similar to what we expect to receive as a minimum from PDL. */ private static KafkaPerson3 createBaseKafkaPerson(String actorId) { KafkaPerson3 kp = new KafkaPerson3(); kp.hentIdenter = new KafkaPerson3.HentIdenter(); kp.hentIdenter.identer = new List(); - kp.hentPerson = new PDL_HentPerson(); + kp.hentPerson = new PdlHentperson(); // just initialise all the lists. kp.hentPerson.adressebeskyttelse = new List(); - kp.hentPerson.bostedsadresse = new List(); + kp.hentPerson.bostedsadresse = new List(); kp.hentPerson.deltBosted = new List(); kp.hentPerson.doedfoedtBarn = new List(); kp.hentPerson.doedsfall = new List(); @@ -1305,7 +1305,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { static void setBostedVegadresse() { Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); KafkaPerson3 kafkaPerson = createBaseKafkaPerson('1122334455666'); - PDL_Bostedsadresse bo = new PDL_Bostedsadresse(); + PdlBostedsadresse bo = new PdlBostedsadresse(); bo.vegadresse = new PDL_Vegadresse(); bo.vegadresse.adressenavn = 'Testveien'; bo.vegadresse.husnummer = '1'; @@ -1351,7 +1351,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { static void setNonHistoricalBosted() { Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); KafkaPerson3 kafkaPerson = createBaseKafkaPerson('1122334455666'); - PDL_Bostedsadresse bo = new PDL_Bostedsadresse(); + PdlBostedsadresse bo = new PdlBostedsadresse(); bo.vegadresse = new PDL_Vegadresse(); bo.vegadresse.adressenavn = 'Gamleveien'; bo.vegadresse.husnummer = '1'; @@ -1364,7 +1364,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { bo.metadata = new PDL_Metadata(); bo.metadata.historisk = true; kafkaPerson.hentPerson.bostedsadresse.add(bo); - bo = new PDL_Bostedsadresse(); + bo = new PdlBostedsadresse(); bo.vegadresse = new PDL_Vegadresse(); bo.vegadresse.adressenavn = 'Nyveien'; bo.vegadresse.husnummer = '2'; diff --git a/force-app/pdl-handler/classes/KafkaPerson3.cls b/force-app/pdl-handler/classes/KafkaPerson3.cls index c16c4ce4..be105dfa 100644 --- a/force-app/pdl-handler/classes/KafkaPerson3.cls +++ b/force-app/pdl-handler/classes/KafkaPerson3.cls @@ -3,7 +3,7 @@ */ public with sharing class KafkaPerson3 { @TestVisible - public PDL_HentPerson hentPerson{get;} + public PdlHentperson hentPerson{get;} @TestVisible public HentIdenter hentIdenter{get;} From 543539d392ceb6f5c76822de0b9692464165a562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 15 Apr 2024 12:56:10 +0200 Subject: [PATCH 103/159] inherit PdlObject in all PdlHentperson attributes breaks KafkaPdlPersondokumentHandlerTest.mapFieldValuesExcludingAddresses --- .../classes/PdlAdressebeskyttelse.cls | 5 + .../PdlAdressebeskyttelse.cls-meta.xml | 5 + .../pdl-apexTypes/classes/PdlDeltbosted.cls | 13 ++ .../classes/PdlDeltbosted.cls-meta.xml | 5 + .../classes/PdlDoedfoedtbarn.cls | 7 + .../classes/PdlDoedfoedtbarn.cls-meta.xml | 5 + .../pdl-apexTypes/classes/PdlDoedsfall.cls | 9 ++ .../classes/PdlDoedsfall.cls-meta.xml | 5 + .../classes/PdlFalskidentitet.cls | 10 ++ .../classes/PdlFalskidentitet.cls-meta.xml | 5 + .../pdl-apexTypes/classes/PdlFoedsel.cls | 12 ++ .../classes/PdlFoedsel.cls-meta.xml | 5 + .../classes/PdlFolkeregisteridentifikator.cls | 10 ++ ...PdlFolkeregisteridentifikator.cls-meta.xml | 5 + .../classes/PdlFolkeregisterpersonstatus.cls | 10 ++ .../PdlFolkeregisterpersonstatus.cls-meta.xml | 5 + .../classes/PdlForelderbarnrelasjon.cls | 12 ++ .../PdlForelderbarnrelasjon.cls-meta.xml | 5 + .../classes/PdlForeldreansvar.cls | 11 ++ .../classes/PdlForeldreansvar.cls-meta.xml | 5 + .../pdl-apexTypes/classes/PdlFullmakt.cls | 15 ++ .../classes/PdlFullmakt.cls-meta.xml | 5 + .../pdl-apexTypes/classes/PdlHentperson.cls | 55 ++++--- .../classes/PdlIdentitetsgrunnlag.cls | 8 + .../PdlIdentitetsgrunnlag.cls-meta.xml | 5 + .../classes/PdlInnflyttingtilnorge.cls | 7 + .../PdlInnflyttingtilnorge.cls-meta.xml | 5 + force-app/pdl-apexTypes/classes/PdlKjoenn.cls | 9 ++ .../classes/PdlKjoenn.cls-meta.xml | 5 + .../classes/PdlKontaktadresse.cls | 21 +++ .../classes/PdlKontaktadresse.cls-meta.xml | 5 + .../PdlKontaktinformasjonfordoedsbo.cls | 13 ++ ...lKontaktinformasjonfordoedsbo.cls-meta.xml | 5 + force-app/pdl-apexTypes/classes/PdlNavn.cls | 12 ++ .../classes/PdlNavn.cls-meta.xml | 5 + .../pdl-apexTypes/classes/PdlOpphold.cls | 10 ++ .../classes/PdlOpphold.cls-meta.xml | 5 + .../classes/PdlOppholdsadresse.cls | 15 ++ .../classes/PdlOppholdsadresse.cls-meta.xml | 5 + .../classes/PdlSikkerhetstiltak.cls | 15 ++ .../classes/PdlSikkerhetstiltak.cls-meta.xml | 5 + .../pdl-apexTypes/classes/PdlSivilstand.cls | 10 ++ .../classes/PdlSivilstand.cls-meta.xml | 5 + .../classes/PdlStatsborgerskap.cls | 11 ++ .../classes/PdlStatsborgerskap.cls-meta.xml | 5 + .../classes/PdlTelefonnummer.cls | 11 ++ .../classes/PdlTelefonnummer.cls-meta.xml | 5 + .../classes/PdlTilrettelagtkommunikasjon.cls | 8 + .../PdlTilrettelagtkommunikasjon.cls-meta.xml | 5 + .../PdlUtenlandskidentifikasjonsnummer.cls | 9 ++ ...enlandskidentifikasjonsnummer.cls-meta.xml | 5 + .../classes/PdlUtflyttingfranorge.cls | 8 + .../PdlUtflyttingfranorge.cls-meta.xml | 5 + .../PdlVergemaalellerfremtidsfullmakt.cls | 12 ++ ...ergemaalellerfremtidsfullmakt.cls-meta.xml | 5 + .../classes/KafkaPdlGtHandlerTest.cls | 58 ++++---- .../classes/KafkaPdlPersondokumentHandler.cls | 36 ++--- .../KafkaPdlPersondokumentHandlerTest.cls | 140 +++++++++--------- 58 files changed, 572 insertions(+), 145 deletions(-) create mode 100644 force-app/pdl-apexTypes/classes/PdlAdressebeskyttelse.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlAdressebeskyttelse.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlDeltbosted.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlDeltbosted.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlDoedfoedtbarn.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlDoedfoedtbarn.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlDoedsfall.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlDoedsfall.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlFalskidentitet.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlFalskidentitet.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlFoedsel.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlFoedsel.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlFolkeregisteridentifikator.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlFolkeregisteridentifikator.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlFolkeregisterpersonstatus.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlFolkeregisterpersonstatus.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlForelderbarnrelasjon.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlForelderbarnrelasjon.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlForeldreansvar.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlForeldreansvar.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlFullmakt.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlFullmakt.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlIdentitetsgrunnlag.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlIdentitetsgrunnlag.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlInnflyttingtilnorge.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlInnflyttingtilnorge.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlKjoenn.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlKjoenn.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlKontaktadresse.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlKontaktadresse.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlKontaktinformasjonfordoedsbo.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlKontaktinformasjonfordoedsbo.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlNavn.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlNavn.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlOpphold.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlOpphold.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlOppholdsadresse.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlOppholdsadresse.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlSikkerhetstiltak.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlSikkerhetstiltak.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlSivilstand.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlSivilstand.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlStatsborgerskap.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlStatsborgerskap.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlTelefonnummer.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlTelefonnummer.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlTilrettelagtkommunikasjon.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlTilrettelagtkommunikasjon.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlUtenlandskidentifikasjonsnummer.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlUtenlandskidentifikasjonsnummer.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlUtflyttingfranorge.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlUtflyttingfranorge.cls-meta.xml create mode 100644 force-app/pdl-apexTypes/classes/PdlVergemaalellerfremtidsfullmakt.cls create mode 100644 force-app/pdl-apexTypes/classes/PdlVergemaalellerfremtidsfullmakt.cls-meta.xml diff --git a/force-app/pdl-apexTypes/classes/PdlAdressebeskyttelse.cls b/force-app/pdl-apexTypes/classes/PdlAdressebeskyttelse.cls new file mode 100644 index 00000000..d01bcbfa --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlAdressebeskyttelse.cls @@ -0,0 +1,5 @@ +public with sharing class PdlAdressebeskyttelse extends PdlObject { + @TestVisible + public PDL_AdressebeskyttelseGradering gradering{ get;} + public PDL_Folkeregistermetadata folkeregistermetadata{ get;} +} diff --git a/force-app/pdl-apexTypes/classes/PdlAdressebeskyttelse.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlAdressebeskyttelse.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlAdressebeskyttelse.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlDeltbosted.cls b/force-app/pdl-apexTypes/classes/PdlDeltbosted.cls new file mode 100644 index 00000000..e0bef4fa --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlDeltbosted.cls @@ -0,0 +1,13 @@ +public with sharing class PdlDeltbosted extends PdlObject { + public Date startdatoForKontrakt{ get;} + public Date sluttdatoForKontrakt{ get;} + public String coAdressenavn{ get;} + public PDL_Vegadresse vegadresse{ get;} + public PDL_Matrikkeladresse matrikkeladresse{ get;} + public PDL_UtenlandskAdresse utenlandskAdresse{ get;} + public PDL_UkjentBosted ukjentBosted{ get;} + public PDL_Folkeregistermetadata folkeregistermetadata{ get;} + + public PdlDeltbosted() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlDeltbosted.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlDeltbosted.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlDeltbosted.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlDoedfoedtbarn.cls b/force-app/pdl-apexTypes/classes/PdlDoedfoedtbarn.cls new file mode 100644 index 00000000..2595e1dc --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlDoedfoedtbarn.cls @@ -0,0 +1,7 @@ +public with sharing class PdlDoedfoedtbarn extends PdlObject { + public Date dato{ get;} + public PDL_Folkeregistermetadata folkeregistermetadata{ get;} + + public PdlDoedfoedtbarn() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlDoedfoedtbarn.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlDoedfoedtbarn.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlDoedfoedtbarn.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlDoedsfall.cls b/force-app/pdl-apexTypes/classes/PdlDoedsfall.cls new file mode 100644 index 00000000..fdd613c3 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlDoedsfall.cls @@ -0,0 +1,9 @@ +public with sharing class PdlDoedsfall extends PdlObject { + @TestVisible + public Date doedsdato{ get;} + @TestVisible + public PDL_Folkeregistermetadata folkeregistermetadata{ get;} + + public PdlDoedsfall() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlDoedsfall.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlDoedsfall.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlDoedsfall.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlFalskidentitet.cls b/force-app/pdl-apexTypes/classes/PdlFalskidentitet.cls new file mode 100644 index 00000000..a4172202 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlFalskidentitet.cls @@ -0,0 +1,10 @@ +public with sharing class PdlFalskidentitet extends PdlObject { + public Boolean erFalsk{ get;} + public String rettIdentitetVedIdentifikasjonsnummer{ get;} + public Boolean rettIdentitetErUkjent{ get;} + public PDL_FalskIdentitetIdentifiserendeInfo rettIdentitetVedOpplysninger{ get;} + public PDL_Folkeregistermetadata folkeregistermetadata{ get;} + + public PdlFalskidentitet() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlFalskidentitet.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlFalskidentitet.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlFalskidentitet.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlFoedsel.cls b/force-app/pdl-apexTypes/classes/PdlFoedsel.cls new file mode 100644 index 00000000..c68bb922 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlFoedsel.cls @@ -0,0 +1,12 @@ +public with sharing class PdlFoedsel extends PdlObject { + public Integer foedselsaar{ get;} + @TestVisible + public Date foedselsdato{ get;} + public String foedeland{ get;} + public String foedested{ get;} + public String foedekommune{ get;} + public PDL_Folkeregistermetadata folkeregistermetadata{ get;} + + public PdlFoedsel() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlFoedsel.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlFoedsel.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlFoedsel.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlFolkeregisteridentifikator.cls b/force-app/pdl-apexTypes/classes/PdlFolkeregisteridentifikator.cls new file mode 100644 index 00000000..bb11913f --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlFolkeregisteridentifikator.cls @@ -0,0 +1,10 @@ +public with sharing class PdlFolkeregisteridentifikator extends PdlObject { + // originaly 'status' and 'type' fields are of String type + @TestVisible + public String identifikasjonsnummer { get; } + @TestVisible + public PDL_IdentStatus status { get; } + @TestVisible + public PDL_IdentType type { get; } + public PDL_Folkeregistermetadata folkeregistermetadata { get; } +} diff --git a/force-app/pdl-apexTypes/classes/PdlFolkeregisteridentifikator.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlFolkeregisteridentifikator.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlFolkeregisteridentifikator.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlFolkeregisterpersonstatus.cls b/force-app/pdl-apexTypes/classes/PdlFolkeregisterpersonstatus.cls new file mode 100644 index 00000000..099fe723 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlFolkeregisterpersonstatus.cls @@ -0,0 +1,10 @@ +public with sharing class PdlFolkeregisterpersonstatus extends PdlObject { + @TestVisible + public String status { get; private set; } + @TestVisible + public String forenkletStatus { get; private set; } + public PDL_Folkeregistermetadata folkeregistermetadata { get; } + + public PdlFolkeregisterpersonstatus() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlFolkeregisterpersonstatus.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlFolkeregisterpersonstatus.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlFolkeregisterpersonstatus.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlForelderbarnrelasjon.cls b/force-app/pdl-apexTypes/classes/PdlForelderbarnrelasjon.cls new file mode 100644 index 00000000..54a55743 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlForelderbarnrelasjon.cls @@ -0,0 +1,12 @@ +public with sharing class PdlForelderbarnrelasjon extends PdlObject { + @TestVisible + public String relatertPersonsIdent { get; private set; } + @TestVisible + public PDL_ForelderBarnRelasjonRolle relatertPersonsRolle { get; private set; } + @TestVisible + public PDL_ForelderBarnRelasjonRolle minRolleForPerson { get; private set; } + public PDL_Folkeregistermetadata folkeregistermetadata { get; } + + public PdlForelderbarnrelasjon() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlForelderbarnrelasjon.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlForelderbarnrelasjon.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlForelderbarnrelasjon.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlForeldreansvar.cls b/force-app/pdl-apexTypes/classes/PdlForeldreansvar.cls new file mode 100644 index 00000000..2f3794c1 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlForeldreansvar.cls @@ -0,0 +1,11 @@ +public with sharing class PdlForeldreansvar extends PdlObject { + + public String ansvar{ get;} + public String ansvarlig{ get;} + public String ansvarssubjekt{ get;} + public PDL_RelatertBiPerson ansvarligUtenIdentifikator{ get;} + public PDL_Folkeregistermetadata folkeregistermetadata{ get;} + + public PdlForeldreansvar() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlForeldreansvar.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlForeldreansvar.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlForeldreansvar.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlFullmakt.cls b/force-app/pdl-apexTypes/classes/PdlFullmakt.cls new file mode 100644 index 00000000..0289602b --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlFullmakt.cls @@ -0,0 +1,15 @@ +public with sharing class PdlFullmakt extends PdlObject { + @TestVisible + public String motpartsPersonident{ get;} + @TestVisible + public PDL_FullmaktsRolle motpartsRolle{ get;} + @TestVisible + public String[] omraader{ get;} + @TestVisible + public Date gyldigFraOgMed{ get;} + @TestVisible + public Date gyldigTilOgMed{ get;} + + public PdlFullmakt() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlFullmakt.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlFullmakt.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlFullmakt.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlHentperson.cls b/force-app/pdl-apexTypes/classes/PdlHentperson.cls index 86ae03af..acdd6136 100644 --- a/force-app/pdl-apexTypes/classes/PdlHentperson.cls +++ b/force-app/pdl-apexTypes/classes/PdlHentperson.cls @@ -2,63 +2,62 @@ * Identical to PDL_HentPerson except its attributes inherit metadata */ public with sharing class PdlHentperson { - @TestVisible - public PDL_Adressebeskyttelse[] adressebeskyttelse{ get;} + public PdlAdressebeskyttelse[] adressebeskyttelse{ get;} @TestVisible public PdlBostedsadresse[] bostedsadresse{ get;} @TestVisible - public PDL_DeltBosted[] deltBosted{ get;} + public PdlDeltbosted[] deltBosted{ get;} @TestVisible - public PDL_DoedfoedtBarn[] doedfoedtBarn{ get;} + public PdlDoedfoedtbarn[] doedfoedtBarn{ get;} @TestVisible - public PDL_Doedsfall[] doedsfall{ get;} + public PdlDoedsfall[] doedsfall{ get;} @TestVisible - public PDL_FalskIdentitet falskIdentitet{ get;} + public PdlFalskidentitet falskIdentitet{ get;} @TestVisible - public PDL_Foedsel[] foedsel{ get;} + public PdlFoedsel[] foedsel{ get;} @TestVisible - public PDL_Folkeregisteridentifikator[] folkeregisteridentifikator{ get;} + public PdlFolkeregisteridentifikator[] folkeregisteridentifikator{ get;} @TestVisible - public PDL_Folkeregisterpersonstatus[] folkeregisterpersonstatus{ get;} + public PdlFolkeregisterpersonstatus[] folkeregisterpersonstatus{ get;} @TestVisible - public PDL_ForelderBarnRelasjon[] forelderBarnRelasjon{ get;} + public PdlForelderbarnrelasjon[] forelderBarnRelasjon{ get;} @TestVisible - public PDL_Foreldreansvar[] foreldreansvar{ get;} + public PdlForeldreansvar[] foreldreansvar{ get;} @TestVisible - public PDL_Fullmakt[] fullmakt{ get;} + public PdlFullmakt[] fullmakt{ get;} @TestVisible - public PDL_Identitetsgrunnlag[] identitetsgrunnlag{ get;} + public PdlIdentitetsgrunnlag[] identitetsgrunnlag{ get;} @TestVisible - public PDL_InnflyttingTilNorge[] innflyttingTilNorge{ get;} + public PdlInnflyttingtilnorge[] innflyttingTilNorge{ get;} @TestVisible - public PDL_Kjoenn[] kjoenn{ get;} + public PdlKjoenn[] kjoenn{ get;} @TestVisible - public PDL_Kontaktadresse[] kontaktadresse{ get;} + public PdlKontaktadresse[] kontaktadresse{ get;} @TestVisible - public PDL_KontaktinformasjonForDoedsbo[] kontaktinformasjonForDoedsbo{ get;} + public PdlKontaktinformasjonfordoedsbo[] kontaktinformasjonForDoedsbo{ get;} @TestVisible - public PDL_Navn[] navn{ get;} + public PdlNavn[] navn{ get;} @TestVisible - public PDL_Opphold[] opphold{ get;} + public PdlOpphold[] opphold{ get;} @TestVisible - public PDL_Oppholdsadresse[] oppholdsadresse{ get;} + public PdlOppholdsadresse[] oppholdsadresse{ get;} @TestVisible - public PDL_Sikkerhetstiltak[] sikkerhetstiltak{ get;} + public PdlSikkerhetstiltak[] sikkerhetstiltak{ get;} @TestVisible - public PDL_Sivilstand[] sivilstand{ get;} + public PdlSivilstand[] sivilstand{ get;} @TestVisible - public PDL_Statsborgerskap[] statsborgerskap{ get;} + public PdlStatsborgerskap[] statsborgerskap{ get;} @TestVisible - public PDL_Telefonnummer[] telefonnummer{ get;} + public PdlTelefonnummer[] telefonnummer{ get;} @TestVisible - public PDL_TilrettelagtKommunikasjon[] tilrettelagtKommunikasjon{ get;} + public PdlTilrettelagtkommunikasjon[] tilrettelagtKommunikasjon{ get;} @TestVisible - public PDL_UtenlandskIdentifikasjonsnummer[] utenlandskIdentifikasjonsnummer{ get;} + public PdlUtenlandskidentifikasjonsnummer[] utenlandskIdentifikasjonsnummer{ get;} @TestVisible - public PDL_UtflyttingFraNorge[] utflyttingFraNorge{ get;} + public PdlUtflyttingfranorge[] utflyttingFraNorge{ get;} @TestVisible - public PDL_VergemaalEllerFremtidsfullmakt[] vergemaalEllerFremtidsfullmakt{ get;} + public PdlVergemaalellerfremtidsfullmakt[] vergemaalEllerFremtidsfullmakt{ get;} public PdlHentperson() { } diff --git a/force-app/pdl-apexTypes/classes/PdlIdentitetsgrunnlag.cls b/force-app/pdl-apexTypes/classes/PdlIdentitetsgrunnlag.cls new file mode 100644 index 00000000..51ffea88 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlIdentitetsgrunnlag.cls @@ -0,0 +1,8 @@ +public with sharing class PdlIdentitetsgrunnlag extends PdlObject { + + public PDL_Identitetsgrunnlagsstatus status{ get;} + public PDL_Folkeregistermetadata folkeregistermetadata{ get;} + + public PdlIdentitetsgrunnlag() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlIdentitetsgrunnlag.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlIdentitetsgrunnlag.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlIdentitetsgrunnlag.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlInnflyttingtilnorge.cls b/force-app/pdl-apexTypes/classes/PdlInnflyttingtilnorge.cls new file mode 100644 index 00000000..ab515d43 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlInnflyttingtilnorge.cls @@ -0,0 +1,7 @@ +public with sharing class PdlInnflyttingtilnorge extends PdlObject { + @TestVisible + public String fraflyttingsland { get; } + @TestVisible + public String fraflyttingsstedIUtlandet { get; } + public PDL_Folkeregistermetadata folkeregistermetadata { get; } +} diff --git a/force-app/pdl-apexTypes/classes/PdlInnflyttingtilnorge.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlInnflyttingtilnorge.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlInnflyttingtilnorge.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlKjoenn.cls b/force-app/pdl-apexTypes/classes/PdlKjoenn.cls new file mode 100644 index 00000000..4c04ebc1 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlKjoenn.cls @@ -0,0 +1,9 @@ +public with sharing class PdlKjoenn extends PdlObject { + + @TestVisible + public PDL_KjoennType kjoenn{ get;} + public PDL_Folkeregistermetadata folkeregistermetadata{ get;} + + public PdlKjoenn() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlKjoenn.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlKjoenn.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlKjoenn.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlKontaktadresse.cls b/force-app/pdl-apexTypes/classes/PdlKontaktadresse.cls new file mode 100644 index 00000000..c00b76ab --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlKontaktadresse.cls @@ -0,0 +1,21 @@ +public with sharing class PdlKontaktadresse extends PdlObject { + + public enum PDL_KontaktadresseType { + Innland, + Utland + } + + public Datetime gyldigFraOgMed{ get;} + public Datetime gyldigTilOgMed{ get;} + public PDL_KontaktadresseType type{ get;} + public String coAdressenavn{ get;} + public PDL_Postboksadresse postboksadresse{ get;} + public PDL_Vegadresse vegadresse{ get;} + public PDL_PostadresseIFrittFormat postadresseIFrittFormat{ get;} + public PDL_UtenlandskAdresse utenlandskAdresse{ get;} + public PDL_UtenlandskAdresseIFrittFormat utenlandskAdresseIFrittFormat{ get;} + public PDL_Folkeregistermetadata folkeregistermetadata{ get;} + + public PdlKontaktadresse() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlKontaktadresse.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlKontaktadresse.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlKontaktadresse.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlKontaktinformasjonfordoedsbo.cls b/force-app/pdl-apexTypes/classes/PdlKontaktinformasjonfordoedsbo.cls new file mode 100644 index 00000000..05fdff31 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlKontaktinformasjonfordoedsbo.cls @@ -0,0 +1,13 @@ +public with sharing class PdlKontaktinformasjonfordoedsbo extends PdlObject { + + public PDL_KontaktinformasjonForDoedsboSkifte skifteform{ get;} + public Date attestutstedelsesdato{ get;} + public PDL_KontaktinformasjonForDoedsboPerson personSomKontakt{ get;} + public PDL_KontaktinformasjonForDoedsboAdvokat advokatSomKontakt{ get;} + public PDL_KontaktinformasjonForDoedsboOrg organisasjonSomKontakt{ get;} + public PDL_KontaktinformasjonForDoedsboAdresse adresse{ get;} + public PDL_Folkeregistermetadata folkeregistermetadata{ get;} + + public PdlKontaktinformasjonfordoedsbo() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlKontaktinformasjonfordoedsbo.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlKontaktinformasjonfordoedsbo.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlKontaktinformasjonfordoedsbo.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlNavn.cls b/force-app/pdl-apexTypes/classes/PdlNavn.cls new file mode 100644 index 00000000..5c96bb8a --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlNavn.cls @@ -0,0 +1,12 @@ +public with sharing class PdlNavn extends PdlObject { + @TestVisible + public String fornavn { get; } + @TestVisible + public String mellomnavn { get; } + @TestVisible + public String etternavn { get; } + public String forkortetNavn { get; } + public PDL_OriginaltNavn originaltNavn { get; } + public Date gyldigFraOgMed { get; } + public PDL_Folkeregistermetadata folkeregistermetadata { get; } +} diff --git a/force-app/pdl-apexTypes/classes/PdlNavn.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlNavn.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlNavn.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlOpphold.cls b/force-app/pdl-apexTypes/classes/PdlOpphold.cls new file mode 100644 index 00000000..f7b2d9ec --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlOpphold.cls @@ -0,0 +1,10 @@ +public with sharing class PdlOpphold extends PdlObject { + + public PDL_Oppholdstillatelse type{ get;} + public Date oppholdFra{ get;} + public Date oppholdTil{ get;} + public PDL_Folkeregistermetadata folkeregistermetadata{ get;} + + public PdlOpphold() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlOpphold.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlOpphold.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlOpphold.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlOppholdsadresse.cls b/force-app/pdl-apexTypes/classes/PdlOppholdsadresse.cls new file mode 100644 index 00000000..2c3606a0 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlOppholdsadresse.cls @@ -0,0 +1,15 @@ +public with sharing class PdlOppholdsadresse extends PdlObject { + public Datetime gyldigFraOgMed{ get;} + public Datetime gyldigTilOgMed{ get;} + public String coAdressenavn{ get;} + public PDL_UtenlandskAdresse utenlandskAdresse{ get;} + @TestVisible + public PDL_Vegadresse vegadresse{ get;} + public PDL_Matrikkeladresse matrikkeladresse{ get;} + public PDL_UkjentBosted ukjentBosted{ get;} + public String oppholdAnnetSted{ get;} + public PDL_Folkeregistermetadata folkeregistermetadata{ get;} + + public PdlOppholdsadresse() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlOppholdsadresse.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlOppholdsadresse.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlOppholdsadresse.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlSikkerhetstiltak.cls b/force-app/pdl-apexTypes/classes/PdlSikkerhetstiltak.cls new file mode 100644 index 00000000..8d9fd86f --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlSikkerhetstiltak.cls @@ -0,0 +1,15 @@ +public with sharing class PdlSikkerhetstiltak extends PdlObject { + @TestVisible + public String tiltakstype{ get;} + @TestVisible + public String beskrivelse{ get;} + @TestVisible + public PDL_SikkerhetstiltakKontaktperson kontaktperson{ get;} + @TestVisible + public Date gyldigFraOgMed{ get;} + @TestVisible + public Date gyldigTilOgMed{ get;} + + public PdlSikkerhetstiltak() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlSikkerhetstiltak.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlSikkerhetstiltak.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlSikkerhetstiltak.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlSivilstand.cls b/force-app/pdl-apexTypes/classes/PdlSivilstand.cls new file mode 100644 index 00000000..126a088f --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlSivilstand.cls @@ -0,0 +1,10 @@ +public with sharing class PdlSivilstand extends PdlObject { + @TestVisible + public PDL_Sivilstandstype type { get; } + @TestVisible + public Date gyldigFraOgMed { get; } + @TestVisible + public String relatertVedSivilstand { get; } + public Date bekreftelsesdato { get; } + public PDL_Folkeregistermetadata folkeregistermetadata { get; } +} diff --git a/force-app/pdl-apexTypes/classes/PdlSivilstand.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlSivilstand.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlSivilstand.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlStatsborgerskap.cls b/force-app/pdl-apexTypes/classes/PdlStatsborgerskap.cls new file mode 100644 index 00000000..da6604cd --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlStatsborgerskap.cls @@ -0,0 +1,11 @@ +public with sharing class PdlStatsborgerskap extends PdlObject { + @TestVisible + public String land{ get;} + public Date bekreftelsesdato{ get;} + public Date gyldigFraOgMed{ get;} + public Date gyldigTilOgMed{ get;} + public PDL_Folkeregistermetadata folkeregistermetadata{ get;} + + public PdlStatsborgerskap() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlStatsborgerskap.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlStatsborgerskap.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlStatsborgerskap.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlTelefonnummer.cls b/force-app/pdl-apexTypes/classes/PdlTelefonnummer.cls new file mode 100644 index 00000000..e6a536ba --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlTelefonnummer.cls @@ -0,0 +1,11 @@ +public with sharing class PdlTelefonnummer extends PdlObject { + @TestVisible + public String landskode{ get;} + @TestVisible + public String nummer{ get;} + @TestVisible + public Integer prioritet{ get;} + + public PdlTelefonnummer() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlTelefonnummer.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlTelefonnummer.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlTelefonnummer.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlTilrettelagtkommunikasjon.cls b/force-app/pdl-apexTypes/classes/PdlTilrettelagtkommunikasjon.cls new file mode 100644 index 00000000..74e14c53 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlTilrettelagtkommunikasjon.cls @@ -0,0 +1,8 @@ +public with sharing class PdlTilrettelagtkommunikasjon extends PdlObject { + @TestVisible + public PDL_Tolk talespraaktolk{ get;} + public PDL_Tolk tegnspraaktolk{ get;} + + public PdlTilrettelagtkommunikasjon() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlTilrettelagtkommunikasjon.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlTilrettelagtkommunikasjon.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlTilrettelagtkommunikasjon.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlUtenlandskidentifikasjonsnummer.cls b/force-app/pdl-apexTypes/classes/PdlUtenlandskidentifikasjonsnummer.cls new file mode 100644 index 00000000..b9de2746 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlUtenlandskidentifikasjonsnummer.cls @@ -0,0 +1,9 @@ +public with sharing class PdlUtenlandskidentifikasjonsnummer extends PdlObject { + public String identifikasjonsnummer{ get;} + public String utstederland{ get;} + public Boolean opphoert{ get;} + public PDL_Folkeregistermetadata folkeregistermetadata{ get;} + + public PdlUtenlandskidentifikasjonsnummer() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlUtenlandskidentifikasjonsnummer.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlUtenlandskidentifikasjonsnummer.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlUtenlandskidentifikasjonsnummer.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlUtflyttingfranorge.cls b/force-app/pdl-apexTypes/classes/PdlUtflyttingfranorge.cls new file mode 100644 index 00000000..3b02a29e --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlUtflyttingfranorge.cls @@ -0,0 +1,8 @@ +public with sharing class PdlUtflyttingfranorge extends PdlObject { + @TestVisible + public String tilflyttingsland { get; } + @TestVisible + public String tilflyttingsstedIUtlandet { get; } + public String utflyttingsdato { get; } + public PDL_Folkeregistermetadata folkeregistermetadata { get; } +} diff --git a/force-app/pdl-apexTypes/classes/PdlUtflyttingfranorge.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlUtflyttingfranorge.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlUtflyttingfranorge.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-apexTypes/classes/PdlVergemaalellerfremtidsfullmakt.cls b/force-app/pdl-apexTypes/classes/PdlVergemaalellerfremtidsfullmakt.cls new file mode 100644 index 00000000..178a7efc --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlVergemaalellerfremtidsfullmakt.cls @@ -0,0 +1,12 @@ +public with sharing class PdlVergemaalellerfremtidsfullmakt extends PdlObject { + @TestVisible + public String type{ get;} + @TestVisible + public String embete{ get;} + @TestVisible + public PDL_VergeEllerFullmektig vergeEllerFullmektig{ get;} + public PDL_Folkeregistermetadata folkeregistermetadata{ get;} + + public PdlVergemaalellerfremtidsfullmakt() { + } +} diff --git a/force-app/pdl-apexTypes/classes/PdlVergemaalellerfremtidsfullmakt.cls-meta.xml b/force-app/pdl-apexTypes/classes/PdlVergemaalellerfremtidsfullmakt.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-apexTypes/classes/PdlVergemaalellerfremtidsfullmakt.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index 4c6a343d..17d9b0f9 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -57,33 +57,33 @@ private with sharing class KafkaPdlGtHandlerTest { kp.hentIdenter.identer = new List(); kp.hentPerson = new PdlHentperson(); // just initialise all the lists. - kp.hentPerson.adressebeskyttelse = new List(); + kp.hentPerson.adressebeskyttelse = new List(); kp.hentPerson.bostedsadresse = new List(); - kp.hentPerson.deltBosted = new List(); - kp.hentPerson.doedfoedtBarn = new List(); - kp.hentPerson.doedsfall = new List(); - kp.hentPerson.foedsel = new List(); - kp.hentPerson.folkeregisteridentifikator = new List(); - kp.hentPerson.folkeregisterpersonstatus = new List(); - kp.hentPerson.forelderBarnRelasjon = new List(); - kp.hentPerson.foreldreansvar = new List(); - kp.hentPerson.fullmakt = new List(); - kp.hentPerson.identitetsgrunnlag = new List(); - kp.hentPerson.innflyttingTilNorge = new List(); - kp.hentPerson.kjoenn = new List(); - kp.hentPerson.kontaktadresse = new List(); - kp.hentPerson.kontaktinformasjonForDoedsbo = new List(); - kp.hentPerson.navn = new List(); - kp.hentPerson.opphold = new List(); - kp.hentPerson.oppholdsadresse = new List(); - kp.hentPerson.sikkerhetstiltak = new List(); - kp.hentPerson.sivilstand = new List(); - kp.hentPerson.statsborgerskap = new List(); - kp.hentPerson.telefonnummer = new List(); - kp.hentPerson.tilrettelagtKommunikasjon = new List(); - kp.hentPerson.utenlandskIdentifikasjonsnummer = new List(); - kp.hentPerson.utflyttingFraNorge = new List(); - kp.hentPerson.vergemaalEllerFremtidsfullmakt = new List(); + kp.hentPerson.deltBosted = new List(); + kp.hentPerson.doedfoedtBarn = new List(); + kp.hentPerson.doedsfall = new List(); + kp.hentPerson.foedsel = new List(); + kp.hentPerson.folkeregisteridentifikator = new List(); + kp.hentPerson.folkeregisterpersonstatus = new List(); + kp.hentPerson.forelderBarnRelasjon = new List(); + kp.hentPerson.foreldreansvar = new List(); + kp.hentPerson.fullmakt = new List(); + kp.hentPerson.identitetsgrunnlag = new List(); + kp.hentPerson.innflyttingTilNorge = new List(); + kp.hentPerson.kjoenn = new List(); + kp.hentPerson.kontaktadresse = new List(); + kp.hentPerson.kontaktinformasjonForDoedsbo = new List(); + kp.hentPerson.navn = new List(); + kp.hentPerson.opphold = new List(); + kp.hentPerson.oppholdsadresse = new List(); + kp.hentPerson.sikkerhetstiltak = new List(); + kp.hentPerson.sivilstand = new List(); + kp.hentPerson.statsborgerskap = new List(); + kp.hentPerson.telefonnummer = new List(); + kp.hentPerson.tilrettelagtKommunikasjon = new List(); + kp.hentPerson.utenlandskIdentifikasjonsnummer = new List(); + kp.hentPerson.utflyttingFraNorge = new List(); + kp.hentPerson.vergemaalEllerFremtidsfullmakt = new List(); // Default values // Ident kp.hentIdenter.identer.add(new PDL_IdentInformasjon()); @@ -91,12 +91,12 @@ private with sharing class KafkaPdlGtHandlerTest { kp.hentIdenter.identer[0].historisk = false; kp.hentIdenter.identer[0].ident = actorId; // Person status - kp.hentPerson.folkeregisterpersonstatus.add(new PDL_Folkeregisterpersonstatus()); + kp.hentPerson.folkeregisterpersonstatus.add(new PdlFolkeregisterpersonstatus()); kp.hentPerson.folkeregisterpersonstatus[0].status = 'bosatt'; // Name - kp.hentPerson.navn.add(new PDL_Navn()); + kp.hentPerson.navn.add(new PdlNavn()); kp.hentPerson.navn[0].etternavn = 'TRESTRESEN'; - kp.hentPerson.adressebeskyttelse.add(new PDL_Adressebeskyttelse()); + kp.hentPerson.adressebeskyttelse.add(new PdlAdressebeskyttelse()); kp.hentPerson.adressebeskyttelse[0].gradering = PDL_AdressebeskyttelseGradering.UGRADERT; return kp; } diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 42713170..a7ae8a00 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -292,7 +292,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess */ private static void setDateOfBirth(Person__c person, PdlHentperson hentPerson) { if (hentPerson.foedsel != null && !hentPerson.foedsel.isEmpty()) { - PDL_Foedsel foedsel = hentPerson.foedsel[hentPerson.foedsel.size() - 1]; + PdlFoedsel foedsel = hentPerson.foedsel[hentPerson.foedsel.size() - 1]; if (foedsel.foedselsdato != null) { DateTime dob = foedsel.foedselsdato; // hack; Date lacks format person.INT_DateOfBirth__c = dob.format('yyyy-MM-dd'); @@ -323,7 +323,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess // Navn if (hentPerson.navn.size() > 0) { - PDL_Navn navn = hentPerson.navn[hentPerson.navn.size() - 1]; + PdlNavn navn = hentPerson.navn[hentPerson.navn.size() - 1]; person.INT_FirstName__c = navn.fornavn ?? ''; person.INT_MiddleName__c = navn.mellomnavn ?? ''; person.INT_LastName__c = navn.etternavn ?? ''; @@ -373,7 +373,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } // telefonnummer - for (PDL_Telefonnummer tlf : hentPerson.telefonnummer) { + for (PdlTelefonnummer tlf : hentPerson.telefonnummer) { if (tlf.prioritet == 1) { person.INT_Phone1__c = tlf.landskode + tlf.nummer; } @@ -492,7 +492,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess // oppholdsadresser // assumption: vegadresse has first pri, then utenlandskAdresse, then ukjentbosted - PDL_Oppholdsadresse opphold = hentPerson.oppholdsadresse.size() > 0 ? hentPerson.oppholdsadresse[0] : null; + PdlOppholdsadresse opphold = hentPerson.oppholdsadresse.size() > 0 ? hentPerson.oppholdsadresse[0] : null; if (opphold?.vegadresse != null) { person.INT_TemporaryAddress__c = addressCreator( new List{ @@ -595,9 +595,9 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * null. */ @TestVisible - private Date getBestDateOfDeath(List deaths) { + private Date getBestDateOfDeath(List deaths) { Map dateAccordingTo = new Map(); - for (PDL_Doedsfall death : deaths) { + for (PdlDoedsfall death : deaths) { dateAccordingTo.put(death.metadata.master.toUpperCase(), Date.valueOf(death.doedsdato)); } if (dateAccordingTo.containsKey('PDL')) { @@ -614,12 +614,12 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * TODO: write test for multiple of these */ @TestVisible - private static String interpreterLanguagesString(PDL_TilrettelagtKommunikasjon[] comms) { + private static String interpreterLanguagesString(PdlTilrettelagtkommunikasjon[] comms) { String[] interpreterLanguages = new List(); if (comms == null || comms.size() == 0) { return null; } - for (PDL_TilrettelagtKommunikasjon comm : comms) { + for (PdlTilrettelagtkommunikasjon comm : comms) { if (comm.talespraaktolk != null) { interpreterLanguages.add(comm.talespraaktolk.spraak); } @@ -658,10 +658,10 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * @param values * @return The list value with the strictest security criteria */ - private String clearanceLevel(List values) { + private String clearanceLevel(List values) { Integer grade, maxGrade = 0; String gradeAsString, returnGrade = 'UGRADERT'; - for (PDL_Adressebeskyttelse protection : values) { + for (PdlAdressebeskyttelse protection : values) { gradeAsString = protection.gradering.name(); grade = ADR_BESKYTTELSES_GRADERING.get(gradeAsString); if (grade > maxGrade) { @@ -764,14 +764,14 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * @param citizenships PDL_Statsborgerskap (list) + * @param citizenships PdlStatsborgerskap (list) * * @return country names joined with ';' */ @TestVisible - private String createCitizenshipString(List citizenships) { + private String createCitizenshipString(List citizenships) { String[] citizenshipStrings = new List(); - for (PDL_Statsborgerskap citizenship : citizenships) { + for (PdlStatsborgerskap citizenship : citizenships) { citizenshipStrings.add(getCountryNameFromIso(citizenship.land)); } return String.join(citizenshipStrings, ';'); @@ -789,7 +789,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess */ private static void setIdents(Person__c person, KafkaPerson3 kp) { PDL_IdentInformasjon[] identer = kp.hentIdenter.identer; - PDL_Folkeregisteridentifikator[] fregIdenter = kp.hentPerson?.folkeregisteridentifikator; + PdlFolkeregisteridentifikator[] fregIdenter = kp.hentPerson?.folkeregisteridentifikator; if (identer != null && identer.isEmpty() == false) { person.INT_NPID__c = Pdl_IdentUtility.getIdentsFromList(identer).npid; } else { @@ -803,13 +803,13 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } } - private static void assignFnrIfAppropriate(Person__c p, PDL_FolkeregisterIdentifikator id) { + private static void assignFnrIfAppropriate(Person__c p, PdlFolkeregisteridentifikator id) { if (id.type == PDL_IdentType.FNR && !id.metadata.historisk && id.status == PDL_IdentStatus.I_BRUK) { p.INT_fnr__c = id.identifikasjonsnummer; } } - private static void assignDnrIfAppropriate(Person__c p, PDL_FolkeregisterIdentifikator id) { + private static void assignDnrIfAppropriate(Person__c p, PdlFolkeregisteridentifikator id) { if (id.type == PDL_IdentType.DNR && (String.isBlank(p.INT_dnr__c) || !id.metadata.historisk)) { p.INT_dnr__c = id.identifikasjonsnummer; } @@ -820,9 +820,9 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess */ private static void setFolkeregisterIdents( Person__c person, - PDL_FolkeregisterIdentifikator[] identifiers + PdlFolkeregisteridentifikator[] identifiers ) { - for (PDL_FolkeregisterIdentifikator id : identifiers) { + for (PdlFolkeregisteridentifikator id : identifiers) { if (String.isNotBlank(id.identifikasjonsnummer)) { // when is this blank? assignFnrIfAppropriate(person, id); assignDnrIfAppropriate(person, id); diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 59dec962..691a0302 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -38,33 +38,33 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { kp.hentIdenter.identer = new List(); kp.hentPerson = new PdlHentperson(); // just initialise all the lists. - kp.hentPerson.adressebeskyttelse = new List(); + kp.hentPerson.adressebeskyttelse = new List(); kp.hentPerson.bostedsadresse = new List(); - kp.hentPerson.deltBosted = new List(); - kp.hentPerson.doedfoedtBarn = new List(); - kp.hentPerson.doedsfall = new List(); - kp.hentPerson.foedsel = new List(); - kp.hentPerson.folkeregisteridentifikator = new List(); - kp.hentPerson.folkeregisterpersonstatus = new List(); - kp.hentPerson.forelderBarnRelasjon = new List(); - kp.hentPerson.foreldreansvar = new List(); - kp.hentPerson.fullmakt = new List(); - kp.hentPerson.identitetsgrunnlag = new List(); - kp.hentPerson.innflyttingTilNorge = new List(); - kp.hentPerson.kjoenn = new List(); - kp.hentPerson.kontaktadresse = new List(); - kp.hentPerson.kontaktinformasjonForDoedsbo = new List(); - kp.hentPerson.navn = new List(); - kp.hentPerson.opphold = new List(); - kp.hentPerson.oppholdsadresse = new List(); - kp.hentPerson.sikkerhetstiltak = new List(); - kp.hentPerson.sivilstand = new List(); - kp.hentPerson.statsborgerskap = new List(); - kp.hentPerson.telefonnummer = new List(); - kp.hentPerson.tilrettelagtKommunikasjon = new List(); - kp.hentPerson.utenlandskIdentifikasjonsnummer = new List(); - kp.hentPerson.utflyttingFraNorge = new List(); - kp.hentPerson.vergemaalEllerFremtidsfullmakt = new List(); + kp.hentPerson.deltBosted = new List(); + kp.hentPerson.doedfoedtBarn = new List(); + kp.hentPerson.doedsfall = new List(); + kp.hentPerson.foedsel = new List(); + kp.hentPerson.folkeregisteridentifikator = new List(); + kp.hentPerson.folkeregisterpersonstatus = new List(); + kp.hentPerson.forelderBarnRelasjon = new List(); + kp.hentPerson.foreldreansvar = new List(); + kp.hentPerson.fullmakt = new List(); + kp.hentPerson.identitetsgrunnlag = new List(); + kp.hentPerson.innflyttingTilNorge = new List(); + kp.hentPerson.kjoenn = new List(); + kp.hentPerson.kontaktadresse = new List(); + kp.hentPerson.kontaktinformasjonForDoedsbo = new List(); + kp.hentPerson.navn = new List(); + kp.hentPerson.opphold = new List(); + kp.hentPerson.oppholdsadresse = new List(); + kp.hentPerson.sikkerhetstiltak = new List(); + kp.hentPerson.sivilstand = new List(); + kp.hentPerson.statsborgerskap = new List(); + kp.hentPerson.telefonnummer = new List(); + kp.hentPerson.tilrettelagtKommunikasjon = new List(); + kp.hentPerson.utenlandskIdentifikasjonsnummer = new List(); + kp.hentPerson.utflyttingFraNorge = new List(); + kp.hentPerson.vergemaalEllerFremtidsfullmakt = new List(); // Default values // Ident kp.hentIdenter.identer.add(new PDL_IdentInformasjon()); @@ -72,12 +72,12 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { kp.hentIdenter.identer[0].historisk = false; kp.hentIdenter.identer[0].ident = actorId; // Person status - kp.hentPerson.folkeregisterpersonstatus.add(new PDL_Folkeregisterpersonstatus()); + kp.hentPerson.folkeregisterpersonstatus.add(new PdlFolkeregisterpersonstatus()); kp.hentPerson.folkeregisterpersonstatus[0].status = 'bosatt'; // Name - kp.hentPerson.navn.add(new PDL_Navn()); + kp.hentPerson.navn.add(new PdlNavn()); kp.hentPerson.navn[0].etternavn = 'TRESTRESEN'; - kp.hentPerson.adressebeskyttelse.add(new PDL_Adressebeskyttelse()); + kp.hentPerson.adressebeskyttelse.add(new PdlAdressebeskyttelse()); kp.hentPerson.adressebeskyttelse[0].gradering = PDL_AdressebeskyttelseGradering.UGRADERT; return kp; } @@ -309,14 +309,14 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { identInfo.historisk = true; identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; kPerson.hentIdenter.identer.add(identInfo); - PDL_FolkeregisterIdentifikator fregIdent = new PDL_FolkeregisterIdentifikator(); + PdlFolkeregisteridentifikator fregIdent = new PdlFolkeregisteridentifikator(); fregIdent.identifikasjonsnummer = '12345678901'; fregIdent.status = PDL_IdentStatus.I_BRUK; fregIdent.type = PDL_IdentType.FNR; fregIdent.metadata = new PDL_Metadata(); fregIdent.metadata.historisk = false; kPerson.hentPerson.folkeregisteridentifikator.add(fregIdent); - fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent = new PdlFolkeregisteridentifikator(); fregIdent.identifikasjonsnummer = '52345678901'; fregIdent.status = PDL_IdentStatus.OPPHOERT; fregIdent.type = PDL_IdentType.DNR; @@ -673,7 +673,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { identInfo.historisk = false; identInfo.ident = '12345678901'; kafkaPerson.hentIdenter.identer.add(identInfo); - PDL_FolkeregisterIdentifikator fregIdent = new PDL_FolkeregisterIdentifikator(); + PdlFolkeregisteridentifikator fregIdent = new PdlFolkeregisteridentifikator(); fregIdent.identifikasjonsnummer = '12345678901'; fregIdent.type = PDL_IdentType.FNR; fregIdent.status = PDL_IdentStatus.I_BRUK; @@ -716,7 +716,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { identInfo.historisk = false; identInfo.ident = '12345678901'; athos.hentIdenter.identer.add(identInfo); - PDL_FolkeregisterIdentifikator fregIdent = new PDL_FolkeregisterIdentifikator(); + PdlFolkeregisteridentifikator fregIdent = new PdlFolkeregisteridentifikator(); fregIdent.status = PDL_IdentStatus.I_BRUK; fregIdent.type = PDL_IdentType.FNR; fregIdent.identifikasjonsnummer = '12345678901'; @@ -729,7 +729,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { identInfo.historisk = false; identInfo.ident = '12345678901'; porthos.hentIdenter.identer.add(identInfo); - fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent = new PdlFolkeregisteridentifikator(); fregIdent.status = PDL_IdentStatus.I_BRUK; fregIdent.type = PDL_IdentType.FNR; fregIdent.identifikasjonsnummer = '12345678901'; @@ -785,7 +785,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { identInfo.historisk = false; identInfo.ident = '12345678901'; laurel.hentIdenter.identer.add(identInfo); - PDL_FolkeregisterIdentifikator fregIdent = new PDL_FolkeregisterIdentifikator(); + PdlFolkeregisteridentifikator fregIdent = new PdlFolkeregisteridentifikator(); fregIdent.status = PDL_IdentStatus.I_BRUK; fregIdent.type = PDL_IdentType.FNR; fregIdent.identifikasjonsnummer = '12345678901'; @@ -798,17 +798,17 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { identInfo.historisk = false; identInfo.ident = '12345678901'; hardy.hentIdenter.identer.add(identInfo); - fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent = new PdlFolkeregisteridentifikator(); fregIdent.status = PDL_IdentStatus.I_BRUK; fregIdent.type = PDL_IdentType.FNR; fregIdent.identifikasjonsnummer = '12345678901'; fregIdent.metadata = new PDL_Metadata(); fregIdent.metadata.historisk = false; hardy.hentPerson.folkeregisteridentifikator.add(fregIdent); - hardy.hentPerson.sikkerhetstiltak = new List(); - hardy.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); - hardy.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); - hardy.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); // wtf? + hardy.hentPerson.sikkerhetstiltak = new List(); + hardy.hentPerson.sikkerhetstiltak.add(new PdlSikkerhetstiltak()); + hardy.hentPerson.sikkerhetstiltak.add(new PdlSikkerhetstiltak()); + hardy.hentPerson.sikkerhetstiltak.add(new PdlSikkerhetstiltak()); // wtf? KafkaMessage__c message1 = createKafkaMessage('1122334455777', null); KafkaMessage__c message2 = createKafkaMessage('1122334455666', laurel); KafkaMessage__c message3 = createKafkaMessage('1122334455666', hardy); @@ -856,7 +856,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { identInfo.historisk = false; identInfo.ident = '12345678901'; athos.hentIdenter.identer.add(identInfo); - PDL_FolkeregisterIdentifikator fregIdent = new PDL_FolkeregisterIdentifikator(); + PdlFolkeregisteridentifikator fregIdent = new PdlFolkeregisteridentifikator(); fregIdent.status = PDL_IdentStatus.I_BRUK; fregIdent.type = PDL_IdentType.FNR; fregIdent.identifikasjonsnummer = '12345678901'; @@ -869,24 +869,24 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { identInfo.historisk = false; identInfo.ident = '12345678901'; porthos.hentIdenter.identer.add(identInfo); - fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent = new PdlFolkeregisteridentifikator(); fregIdent.status = PDL_IdentStatus.I_BRUK; fregIdent.type = PDL_IdentType.FNR; fregIdent.identifikasjonsnummer = '12345678901'; fregIdent.metadata = new PDL_Metadata(); fregIdent.metadata.historisk = false; porthos.hentPerson.folkeregisteridentifikator.add(fregIdent); - porthos.hentPerson.sikkerhetstiltak = new List(); - porthos.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); - porthos.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); - porthos.hentPerson.sikkerhetstiltak.add(new PDL_Sikkerhetstiltak()); + porthos.hentPerson.sikkerhetstiltak = new List(); + porthos.hentPerson.sikkerhetstiltak.add(new PdlSikkerhetstiltak()); + porthos.hentPerson.sikkerhetstiltak.add(new PdlSikkerhetstiltak()); + porthos.hentPerson.sikkerhetstiltak.add(new PdlSikkerhetstiltak()); KafkaPerson3 aramis = createBaseKafkaPerson('1122334455999'); identInfo = new PDL_IdentInformasjon(); identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; identInfo.historisk = false; identInfo.ident = '12345678902'; aramis.hentIdenter.identer.add(identInfo); - fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent = new PdlFolkeregisteridentifikator(); fregIdent.status = PDL_IdentStatus.I_BRUK; fregIdent.type = PDL_IdentType.FNR; fregIdent.identifikasjonsnummer = '12345678902'; @@ -997,14 +997,14 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { identInfo.historisk = false; identInfo.ident = '52345678901'; kafkaPerson.hentIdenter.identer.add(identInfo); - PDL_FolkeregisterIdentifikator fregIdent = new PDL_FolkeregisterIdentifikator(); + PdlFolkeregisteridentifikator fregIdent = new PdlFolkeregisteridentifikator(); fregIdent.identifikasjonsnummer = '52345678901'; fregIdent.type = PDL_IdentType.DNR; fregIdent.status = PDL_IdentStatus.I_BRUK; fregIdent.metadata = new PDL_Metadata(); fregIdent.metadata.historisk = false; kafkaPerson.hentPerson.folkeregisteridentifikator.add(fregIdent); - kafkaPerson.hentPerson.folkeregisterpersonstatus.add(new PDL_Folkeregisterpersonstatus()); + kafkaPerson.hentPerson.folkeregisterpersonstatus.add(new PdlFolkeregisterpersonstatus()); kafkaPerson.hentPerson.folkeregisterpersonstatus[0].status = 'bosatt'; // second message; now also with active freg-ident: dnr KafkaMessage__c message2 = createKafkaMessage('1122334455666', kafkaPerson); @@ -1018,7 +1018,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { identInfo.historisk = false; identInfo.ident = '11345678901'; kafkaPerson.hentIdenter.identer.add(identInfo); - fregIdent = new PDL_FolkeregisterIdentifikator(); + fregIdent = new PdlFolkeregisteridentifikator(); fregIdent.identifikasjonsnummer = '11345678901'; fregIdent.type = PDL_IdentType.FNR; fregIdent.status = PDL_IdentStatus.I_BRUK; @@ -1100,7 +1100,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { identInfo.historisk = false; identInfo.ident = '12345678901'; kafkaPerson.hentIdenter.identer.add(identInfo); - PDL_FolkeregisterIdentifikator fregIdent = new PDL_FolkeregisterIdentifikator(); + PdlFolkeregisteridentifikator fregIdent = new PdlFolkeregisteridentifikator(); fregIdent.identifikasjonsnummer = '12345678901'; fregIdent.type = PDL_IdentType.FNR; fregIdent.status = PDL_IdentStatus.I_BRUK; @@ -1110,14 +1110,14 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { // surname already provided by createBaseKafkaPerson kafkaPerson.hentPerson.navn[0].fornavn = 'TREST'; kafkaPerson.hentPerson.navn[0].mellomnavn = 'T.'; - PDL_Foedsel foedsel = new PDL_Foedsel(); + PdlFoedsel foedsel = new PdlFoedsel(); foedsel.foedselsdato = Date.valueOf('2020-02-25'); kafkaPerson.hentPerson.foedsel.add(foedsel); - PDL_InnflyttingTilNorge innflytting = new PDL_InnflyttingTilNorge(); + PdlInnflyttingtilnorge innflytting = new PdlInnflyttingtilnorge(); innflytting.fraflyttingsland = 'IND'; innflytting.fraflyttingsstedIUtlandet = 'Delhi'; kafkaPerson.hentPerson.innflyttingTilNorge.add(innflytting); - PDL_Sikkerhetstiltak tiltak = new PDL_Sikkerhetstiltak(); + PdlSikkerhetstiltak tiltak = new PdlSikkerhetstiltak(); tiltak.beskrivelse = 'Telefonisk utestengelse'; tiltak.tiltaksType = 'TFUS'; tiltak.gyldigFraOgMed = Date.valueOf('2020-12-14'); @@ -1126,48 +1126,48 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { tiltak.kontaktperson.personident = 'Z000000'; tiltak.kontaktperson.enhet = '0000'; kafkaPerson.hentPerson.sikkerhetstiltak.add(tiltak); - PDL_Statsborgerskap statsborgerskap = new PDL_Statsborgerskap(); + PdlStatsborgerskap statsborgerskap = new PdlStatsborgerskap(); statsborgerskap.land = 'NOR'; kafkaPerson.hentPerson.statsborgerskap.add(statsborgerskap); - PDL_Sivilstand sivilstand = new PDL_Sivilstand(); + PdlSivilstand sivilstand = new PdlSivilstand(); sivilstand.type = PDL_Sivilstandstype.GIFT; sivilstand.gyldigFraOgMed = Date.newInstance(2001, 6, 20); sivilstand.relatertVedSivilstand = '12345678910'; kafkaPerson.hentPerson.sivilstand.add(sivilstand); - PDL_Kjoenn kjoenn = new PDL_Kjoenn(); + PdlKjoenn kjoenn = new PdlKjoenn(); kjoenn.kjoenn = PDL_KjoennType.MANN; kafkaPerson.hentPerson.kjoenn.add(kjoenn); - PDL_Doedsfall doedsfall = new PDL_Doedsfall(); + PdlDoedsfall doedsfall = new PdlDoedsfall(); doedsfall.doedsdato = Date.valueOf('2019-01-29'); doedsfall.metadata = new PDL_Metadata(); doedsfall.metadata.master = 'FREG'; kafkaPerson.hentPerson.doedsfall.add(doedsfall); - PDL_Telefonnummer nummer = new PDL_Telefonnummer(); + PdlTelefonnummer nummer = new PdlTelefonnummer(); nummer.landskode = '+46'; nummer.nummer = '0765-43 21 07'; nummer.prioritet = 2; kafkaPerson.hentPerson.telefonnummer.add(nummer); - nummer = new PDL_Telefonnummer(); + nummer = new PdlTelefonnummer(); nummer.landskode = '+47'; nummer.nummer = '987 65 432'; nummer.prioritet = 1; kafkaPerson.hentPerson.telefonnummer.add(nummer); - PDL_UtflyttingFraNorge utflytting = new PDL_UtflyttingFraNorge(); + PdlUtflyttingfranorge utflytting = new PdlUtflyttingfranorge(); utflytting.tilflyttingsland = 'IND'; utflytting.tilflyttingsstedIUtlandet = 'Delhi'; kafkaPerson.hentPerson.utflyttingFraNorge.add(utflytting); - PDL_TilrettelagtKommunikasjon kom = new PDL_TilrettelagtKommunikasjon(); + PdlTilrettelagtkommunikasjon kom = new PdlTilrettelagtkommunikasjon(); kom.talespraaktolk = new PDL_Tolk(); kom.talespraaktolk.spraak = 'NO'; kafkaPerson.hentPerson.tilrettelagtKommunikasjon.add(kom); - PDL_Fullmakt fullmakt = new PDL_Fullmakt(); + PdlFullmakt fullmakt = new PdlFullmakt(); fullmakt.motpartsRolle = PDL_FullmaktsRolle.FULLMEKTIG; fullmakt.motpartsPersonident = '12345678910'; fullmakt.omraader = new List{ 'DAG' }; fullmakt.gyldigFraOgMed = Date.valueOf('2020-02-14'); fullmakt.gyldigTilOgMed = Date.valueOf('2020-02-28'); kafkaPerson.hentPerson.fullmakt.add(fullmakt); - PDL_VergemaalEllerFremtidsfullmakt verge = new PDL_VergemaalEllerFremtidsfullmakt(); + PdlVergemaalellerfremtidsfullmakt verge = new PdlVergemaalellerfremtidsfullmakt(); verge.type = 'stadfestetFremtidsfullmakt'; verge.embete = 'Statsforvalter'; verge.vergeEllerFullmektig = new PDL_VergeEllerFullmektig(); @@ -1227,20 +1227,20 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { */ @isTest static void testHighestGradeApplies() { - PDL_Adressebeskyttelse ungraded = new PDL_Adressebeskyttelse(); + PdlAdressebeskyttelse ungraded = new PdlAdressebeskyttelse(); ungraded.gradering = PDL_AdressebeskyttelseGradering.UGRADERT; - PDL_Adressebeskyttelse confidential = new PDL_Adressebeskyttelse(); + PdlAdressebeskyttelse confidential = new PdlAdressebeskyttelse(); confidential.gradering = PDL_AdressebeskyttelseGradering.FORTROLIG; - PDL_Adressebeskyttelse strictlyConfidential = new PDL_Adressebeskyttelse(); + PdlAdressebeskyttelse strictlyConfidential = new PdlAdressebeskyttelse(); strictlyConfidential.gradering = PDL_AdressebeskyttelseGradering.STRENGT_FORTROLIG; - PDL_Adressebeskyttelse strictConfAbroad = new PDL_Adressebeskyttelse(); + PdlAdressebeskyttelse strictConfAbroad = new PdlAdressebeskyttelse(); strictConfAbroad.gradering = PDL_AdressebeskyttelseGradering.STRENGT_FORTROLIG_UTLAND; KafkaPerson3 fiferPig = createBaseKafkaPerson('8849688496884', '88496884968'); KafkaPerson3 fiddlerPig = createBaseKafkaPerson('8154968154968', '81549681549'); KafkaPerson3 practicalPig = createBaseKafkaPerson('9471759694717', '94717596947'); KafkaPerson3 bigBadWolf = createBaseKafkaPerson('9691858969185', '96918589691'); // strip existing protection, empty list should default to UGRADERT - bigBadWolf.hentPerson.adressebeskyttelse = new List(); + bigBadWolf.hentPerson.adressebeskyttelse = new List(); // add protection fiddlerPig.hentPerson.adressebeskyttelse.add(confidential); fiddlerPig.hentPerson.adressebeskyttelse.add(strictConfAbroad); @@ -1455,7 +1455,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { static void setOppholdVegadresse() { Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); KafkaPerson3 kafkaPerson = createBaseKafkaPerson('11223344556'); - PDL_Oppholdsadresse opphold = new PDL_Oppholdsadresse(); + PdlOppholdsadresse opphold = new PdlOppholdsadresse(); opphold.vegadresse = new PDL_Vegadresse(); opphold.vegadresse.adressenavn = 'Testveien'; opphold.vegadresse.husnummer = '1'; From 57faf0f5c037d3c0a140a4a464155ed2d4339d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 15 Apr 2024 13:52:30 +0200 Subject: [PATCH 104/159] pass test by ordering metadata first --- .../classes/KafkaPdlPersondokumentHandlerTest.cls | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 691a0302..e751caf5 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1199,7 +1199,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('Bosatt', person.INT_LegalStatus__c); Assert.isNotNull(person.INT_MovedFromCountry__c); Assert.areEqual('Delhi', person.INT_MovedFromPlace__c); - Assert.areEqual('[{"tiltakstype":"TFUS","metadata":null,"kontaktperson":{"personident":"Z000000","enhet":"0000"},"gyldigTilOgMed":"2020-12-20","gyldigFraOgMed":"2020-12-14","beskrivelse":"Telefonisk utestengelse"}]', person.INT_SecurityMeasures__c); + Assert.areEqual('[{"metadata":null,"tiltakstype":"TFUS","kontaktperson":{"personident":"Z000000","enhet":"0000"},"gyldigTilOgMed":"2020-12-20","gyldigFraOgMed":"2020-12-14","beskrivelse":"Telefonisk utestengelse"}]', person.INT_SecurityMeasures__c); Assert.areEqual('Norge', person.INT_Citizenships__c); Assert.areEqual('GIFT', person.INT_MaritalStatus__c); Assert.areEqual(Date.newInstance(2001, 6, 20), person.INT_MaritalStatusDate__c); @@ -1210,8 +1210,8 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.isNotNull(person.INT_MovedToCountry__c); Assert.areEqual('Delhi', person.INT_MovedToPlace__c); Assert.areEqual('NO', person.INT_SpokenLanguageIntepreter__c); - Assert.areEqual('[{"omraader":["DAG"],"motpartsRolle":"FULLMEKTIG","motpartsPersonident":"12345678910","metadata":null,"gyldigTilOgMed":"2020-02-28","gyldigFraOgMed":"2020-02-14"}]', person.INT_PowerOfAttorney__c); - Assert.areEqual('[{"vergeEllerFullmektig":{"omfangetErInnenPersonligOmraade":true,"omfang":"Personlige og/eller økonomiske interesser","navn":null,"motpartsPersonident":"12345678910"},"type":"stadfestetFremtidsfullmakt","metadata":null,"folkeregistermetadata":null,"embete":"Statsforvalter"}]', person.INT_GuardianshipOrFuturePowerOfAttorney__c); + Assert.areEqual('[{"metadata":null,"omraader":["DAG"],"motpartsRolle":"FULLMEKTIG","motpartsPersonident":"12345678910","gyldigTilOgMed":"2020-02-28","gyldigFraOgMed":"2020-02-14"}]', person.INT_PowerOfAttorney__c); + Assert.areEqual('[{"metadata":null,"vergeEllerFullmektig":{"omfangetErInnenPersonligOmraade":true,"omfang":"Personlige og/eller økonomiske interesser","navn":null,"motpartsPersonident":"12345678910"},"type":"stadfestetFremtidsfullmakt","folkeregistermetadata":null,"embete":"Statsforvalter"}]', person.INT_GuardianshipOrFuturePowerOfAttorney__c); Assert.areEqual('UGRADERT', person.INT_Confidential__c); Assert.areEqual(Date.newInstance(2019, 1, 29), person.INT_DateOfDeath__c); Assert.areEqual(true, person.INT_IsDeceased__c); From cbdda382a36d674b1d35aa836c12eb58ee7d04b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 15 Apr 2024 14:01:21 +0200 Subject: [PATCH 105/159] drop warning about list sizes not being 1 --- .../classes/KafkaPdlPersondokumentHandler.cls | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index a7ae8a00..6388d619 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -691,18 +691,10 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } else { if (hentIdenter.identer.size() == 0) { throw new PdlMissingEntryException('No idents found'); } } + // consider not making this a warning if it happens often if (hp.navn.size() == 0) { throw new PdlMissingEntryException('No name found'); } if (hp.navn[0].etternavn == null) {throw new PdlMissingEntryException('No etternavn found'); } - // Check for list sizes greater than one - // TODO: consider reducing in here rather than in proxy - if (hp.bostedsadresse.size() > 1) { objectsFailingValidation.add('bostedsadresse'); } - if (hp.oppholdsadresse.size() > 1) { objectsFailingValidation.add('oppholdsadresse'); } - if (objectsFailingValidation.size() > 0) { - throw new pdlListContainsTooManyEntriesException( - 'Multiple objects received for ' + - String.join(objectsFailingValidation, ',') - ); - } + // No longer check for list sizes greater than one, that's to be expected. } /** @@ -1003,9 +995,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess message.CRM_Status__c = status; } - public class PdlListContainsTooManyEntriesException extends Exception { - } - public class PdlMissingEntryException extends Exception { } From 4e94523f0e0b726d7b3016b5a6490050a70cd07a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 15 Apr 2024 14:11:33 +0200 Subject: [PATCH 106/159] clarify comments, use application domain PDL --- .../classes/KafkaPdlPersondokumentHandler.cls | 55 +++++++++++-------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 6388d619..dfd5fb94 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -27,7 +27,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess ] ); - private Set existingActors; + private Set existingActors = new Set(); private LoggerUtility logger = new LoggerUtility('PDL'); @@ -52,41 +52,50 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * Process messages. Warn or error (i.e. set CRM_Status__c on the - * KafkaMessage__c) according to some criteria on which I'm not entirely - * clear yet: - * - PdlIdentException seems to raise an error. + * Process messages. Catch various exceptions and then warn or error (i.e. + * set CRM_Status__c on the KafkaMessage__c) according to some criteria + * which seem to be the following: + * - any PdlIdentException should be treated like an error + * - any other Exception is: + * - error, if person already exists + * - warning, if person doesn't exist */ public void processMessages(List messages) { - Map personFromActorId = new Map(); + // map for storing potential gt info that already exists Map gtFromActorId = new Map(); - existingActors = new Set(); + // maps to be set only after successful person creation + Map personFromActorId = new Map(); Map messageFromActorId = new Map(); // If we have a message where the created date is older than last // updated, set it to error so that we can investigate it. If we have a // tombstone without a person in Salesforce, set it to processed. + // clobbers _messages_ in the sense that its CRM_Status__c may change. checkLastUpdatedAndTombStones(messages); // If we have INT_GT... fields already saved, we would like to keep them. fetchGeografiskTilknytning(gtFromActorId, messages); - // Errors are caught and saved on each KafkaMessage record for (KafkaMessage__c msg : messages) { + // exclude the ones modified by checkLastUpdatedAndTombStones if (msg.CRM_Status__c == KafkaMessageService.STATUS_PENDING) { try { Person__c person = createPersonRecord(msg, gtFromActorId.get(msg.CRM_Key__c)); + // if success, then: personFromActorId.put(person.INT_ActorId__c, person); messageFromActorId.put(person.INT_ActorId__c, msg); msg.CRM_Status__c = KafkaMessageService.STATUS_PROCESSED; } catch (PdlIdentException e) { + // big mistake. String errorMsg = e.getTypeName() + ': ' + e.getMessage() + ' (' + e.getLineNumber() + ')'; setMessageError(errorMsg, msg, KafkaMessageService.STATUS_ERROR); logger.error( 'Caught PdlIdentException when attempting to create Person__c:\n' + e.getMessage() + - '\n Kafka key reference: ' + + '\nKafka key reference: ' + msg.CRM_Key__c, null ); } catch (Exception e) { + // big mistake if person already exists, otherwise small + // mistake. String errorMsg = e.getTypeName() + ': ' + e.getMessage() + ' (' + e.getLineNumber() + ')'; setMessageError(errorMsg, msg); if (msg.CRM_Status__c == KafkaMessageService.STATUS_ERROR) { @@ -95,15 +104,15 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess 'Kafka key reference: ' + msg.CRM_Key__c, null, - CRM_ApplicationDomain.domain.NKS + CRM_ApplicationDomain.domain.PDL ); } else if (msg.CRM_Status__c == KafkaMessageService.STATUS_WARNING) { logger.warning( 'Warning creating Person__c from PDL Kafka message. ' + - '\n Kafka key reference: ' + + '\nKafka key reference: ' + msg.CRM_Key__c, null, - CRM_ApplicationDomain.domain.NKS + CRM_ApplicationDomain.domain.PDL ); } } @@ -130,7 +139,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess '\n Kafka key reference: ' + messageList[i].CRM_Key__c, null, - CRM_ApplicationDomain.domain.NKS + CRM_ApplicationDomain.domain.PDL ); } else if (messageList[i].CRM_Status__c == KafkaMessageService.STATUS_WARNING) { logger.warning( @@ -138,7 +147,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess '\n Kafka key reference: ' + messageList[i].CRM_Key__c, null, - CRM_ApplicationDomain.domain.NKS + CRM_ApplicationDomain.domain.PDL ); } } @@ -281,7 +290,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess throw new PdlIdentException('Failed to parse kafka person: ' + e.getTypeName() + ': ' + e.getMessage() + ' (' + e.getLineNumber() + ')'); } - validateListSizes(kafkaPerson); // assume there's a good reason to do this + validateListSizes(kafkaPerson); person = mapFieldValues(person, kafkaPerson, gtPerson); return person; } @@ -674,10 +683,9 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess /** * Validate list sizes and if errors are found, throw exception. - * This will be caught and stored on the relevant Kafka Message as a - * warning, info, error, whatever. - * Previously the proxy would reduce a list down to contain only the - * non-historical one. Now we need to do this ourselves. + * This prevents the person from being saved, and the exception is caught + * and stored on the relevant Kafka Message as a warning, info, error, + * whatever. * @param kafkaPerson Kafka person to validate */ private void validateListSizes(KafkaPerson3 kafkaPerson) { @@ -691,10 +699,8 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } else { if (hentIdenter.identer.size() == 0) { throw new PdlMissingEntryException('No idents found'); } } - // consider not making this a warning if it happens often if (hp.navn.size() == 0) { throw new PdlMissingEntryException('No name found'); } if (hp.navn[0].etternavn == null) {throw new PdlMissingEntryException('No etternavn found'); } - // No longer check for list sizes greater than one, that's to be expected. } /** @@ -749,7 +755,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess '\n ISO Code: ' + isoCode, null, - CRM_ApplicationDomain.domain.NKS + CRM_ApplicationDomain.domain.PDL ); } return null; @@ -981,6 +987,11 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } } + /** + * Let's make errors as complicated as possible. This function sets + * CRM_Status__c to Error if the actor ID exists, otherwise it sets it to + * Warning, for some reason. + */ private void setMessageError(String errorMsg, KafkaMessage__c message) { String aktoer_id = message.CRM_Key__c; if (existingActors != null && existingActors.contains(aktoer_id)) { From 20966ac2de66fa3c5af977bd34b30923f01accbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 15 Apr 2024 14:53:00 +0200 Subject: [PATCH 107/159] rewrite fields similarly to bostedsadresse foedsel, navn, status, innflytning --- .../classes/KafkaPdlPersondokumentHandler.cls | 71 ++++++++----------- 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index dfd5fb94..1fdac35d 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -295,19 +295,34 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess return person; } + /** + * Fetches the non-historical entry out of a list of entries. + * Returns first entry where metadata is + * - null (implicitly active) + * - explicitly not historical + * Occasionally there may be multiple valid entries, e.g. one from FREG, one from PDL. + * Handle that if it becomes necessary. + */ + private static PdlObject getActiveOrNone(PdlObject[] pos) { + for(PdlObject po : pos) { + if(!(po.metadata?.historisk ?? false)) { + return po; + } + } + return null; + } + /** * Set date (or year) of birth. * Takes Date or Integer, sets String. */ private static void setDateOfBirth(Person__c person, PdlHentperson hentPerson) { - if (hentPerson.foedsel != null && !hentPerson.foedsel.isEmpty()) { - PdlFoedsel foedsel = hentPerson.foedsel[hentPerson.foedsel.size() - 1]; - if (foedsel.foedselsdato != null) { - DateTime dob = foedsel.foedselsdato; // hack; Date lacks format - person.INT_DateOfBirth__c = dob.format('yyyy-MM-dd'); - } else if(foedsel.foedselsaar != null) { - person.INT_DateOfBirth__c = '' + foedsel.foedselsaar; - } + PdlFoedsel foedsel = (PdlFoedsel)getActiveOrNone(hentPerson.foedsel); + if (foedsel?.foedselsdato != null) { + DateTime dob = foedsel.foedselsdato; // hack; Date lacks format + person.INT_DateOfBirth__c = dob.format('yyyy-MM-dd'); + } else if(foedsel?.foedselsaar != null) { + person.INT_DateOfBirth__c = '' + foedsel.foedselsaar; } } @@ -331,25 +346,18 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess setDateOfBirth(person, hentPerson); // Navn - if (hentPerson.navn.size() > 0) { - PdlNavn navn = hentPerson.navn[hentPerson.navn.size() - 1]; - person.INT_FirstName__c = navn.fornavn ?? ''; - person.INT_MiddleName__c = navn.mellomnavn ?? ''; - person.INT_LastName__c = navn.etternavn ?? ''; - } + PdlNavn navn = (PdlNavn)getActiveOrNone(hentPerson.navn); + person.INT_FirstName__c = navn.fornavn ?? ''; + person.INT_MiddleName__c = navn.mellomnavn ?? ''; + person.INT_LastName__c = navn.etternavn ?? ''; // folkeregisterpersonstatus - if (hentPerson.folkeregisterpersonstatus.size() > 0) { - person.INT_LegalStatus__c = hentPerson.folkeregisterpersonstatus[0].status; - } + person.INT_LegalStatus__c = ((PdlFolkeregisterpersonstatus)getActiveOrNone(hentPerson.folkeregisterpersonstatus))?.status; // InnflytningTilNorge - if (hentPerson.innflyttingTilNorge.size() > 0) { - person.INT_MovedFromCountry__c = getCountryIdFromIso( - hentPerson.innflyttingTilNorge[hentPerson.innflyttingTilNorge.size() - 1].fraflyttingsland - ); - person.INT_MovedFromPlace__c = hentPerson.innflyttingTilNorge[hentPerson.innflyttingTilNorge.size() - 1].fraflyttingsstedIUtlandet; - } + PdlInnflyttingtilnorge innflytting = (PdlInnflyttingtilnorge)getActiveOrNone(hentPerson.innflyttingTilNorge); + person.INT_MovedFromCountry__c = getCountryIdFromIso(innflytting?.fraflyttingsland); + person.INT_MovedFromPlace__c = innflytting?.fraflyttingsstedIUtlandet; // adressebeskyttelse person.INT_Confidential__c = clearanceLevel(hentPerson.adressebeskyttelse); @@ -436,23 +444,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess k.z}); } - /** - * Fetches the non-historical entry out of a list of entries. - * Returns first entry where metadata is - * - null (implicitly active) - * - explicitly not historical - * Occasionally there may be multiple valid entries, e.g. one from FREG, one from PDL. - * Handle that if it becomes necessary. - */ - private PdlObject getActiveOrNone(PdlObject[] pos) { - for(PdlObject po : pos) { - if(!(po.metadata?.historisk ?? false)) { - return po; - } - } - return null; - } - /** * Sets the address according to the priority seen within the method. Also * sets municipality and district numbers, as long as they would not From 07cc67f42095fd06b18ab6aee1ea8c39f82e5e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 16 Apr 2024 18:49:39 +0200 Subject: [PATCH 108/159] rewrite address protection (ugly, loosely typed) --- .../classes/KafkaPdlPersondokumentHandler.cls | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 1fdac35d..6a4c0144 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -296,12 +296,27 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * Fetches the non-historical entry out of a list of entries. + * Fetches all non-historical entries. * Returns first entry where metadata is * - null (implicitly active) * - explicitly not historical * Occasionally there may be multiple valid entries, e.g. one from FREG, one from PDL. * Handle that if it becomes necessary. + * Note: seems each element of the returned list has to be cast separately. + */ + private static PdlObject[] getAllActive(PdlObject[] pos) { + PdlObject[] ret = new List(); + for(PdlObject po : pos) { + if(!(po.metadata?.historisk ?? false)) { + ret.add(po); + } + } + return ret; + } + + /** + * Fetches the first non-historical entry out of a list of entries. + * Like getAllActive, but returns after the first match. */ private static PdlObject getActiveOrNone(PdlObject[] pos) { for(PdlObject po : pos) { @@ -360,7 +375,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess person.INT_MovedFromPlace__c = innflytting?.fraflyttingsstedIUtlandet; // adressebeskyttelse - person.INT_Confidential__c = clearanceLevel(hentPerson.adressebeskyttelse); + person.INT_Confidential__c = clearanceLevel(getAllActive(hentPerson.adressebeskyttelse)); // sikkerhetstiltak person.INT_SecurityMeasures__c = JSON.serialize(kafkaPerson.hentPerson.sikkerhetstiltak); @@ -658,10 +673,11 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * @param values * @return The list value with the strictest security criteria */ - private String clearanceLevel(List values) { + private String clearanceLevel(List values) { Integer grade, maxGrade = 0; String gradeAsString, returnGrade = 'UGRADERT'; - for (PdlAdressebeskyttelse protection : values) { + for (PdlObject protObj : values) { + PdlAdressebeskyttelse protection = (PdlAdressebeskyttelse)protObj; gradeAsString = protection.gradering.name(); grade = ADR_BESKYTTELSES_GRADERING.get(gradeAsString); if (grade > maxGrade) { From c91ac68a726e3097014245ccbbc435d1c7e5be23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 17 Apr 2024 18:08:10 +0200 Subject: [PATCH 109/159] rewrite the rest of the fields --- force-app/pdl-apexTypes/classes/PdlObject.cls | 2 +- .../classes/KafkaPdlPersondokumentHandler.cls | 98 ++++++++++--------- 2 files changed, 52 insertions(+), 48 deletions(-) diff --git a/force-app/pdl-apexTypes/classes/PdlObject.cls b/force-app/pdl-apexTypes/classes/PdlObject.cls index 4883c1e6..a2b5e371 100644 --- a/force-app/pdl-apexTypes/classes/PdlObject.cls +++ b/force-app/pdl-apexTypes/classes/PdlObject.cls @@ -1,7 +1,7 @@ /** * Common elements of all Pdl classes */ -public virtual class PdlObject { +public abstract class PdlObject { @TestVisible public PDL_Metadata metadata{ get;} } diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 6a4c0144..09d493a6 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -297,11 +297,9 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess /** * Fetches all non-historical entries. - * Returns first entry where metadata is + * Returns entries where metadata is * - null (implicitly active) * - explicitly not historical - * Occasionally there may be multiple valid entries, e.g. one from FREG, one from PDL. - * Handle that if it becomes necessary. * Note: seems each element of the returned list has to be cast separately. */ private static PdlObject[] getAllActive(PdlObject[] pos) { @@ -314,11 +312,23 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess return ret; } + /** + * Like getAllActive but returns: + * - null instead of an empty list. + * - a serialized string instead of a list of objects. + */ + private static String getSerializedActiveOrNull(PdlObject[] pos) { + PdlObject[] activePos = getAllActive(pos); + return activePos.size() > 0 ? JSON.serialize(activePos) : null; + } + /** * Fetches the first non-historical entry out of a list of entries. - * Like getAllActive, but returns after the first match. + * Similar to getAllActive, but returns after the first match. + * Occasionally there may be multiple valid entries, e.g. one from FREG, one + * from PDL. Handle that if it becomes necessary. */ - private static PdlObject getActiveOrNone(PdlObject[] pos) { + private static PdlObject getFirstActiveOrNull(PdlObject[] pos) { for(PdlObject po : pos) { if(!(po.metadata?.historisk ?? false)) { return po; @@ -332,7 +342,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * Takes Date or Integer, sets String. */ private static void setDateOfBirth(Person__c person, PdlHentperson hentPerson) { - PdlFoedsel foedsel = (PdlFoedsel)getActiveOrNone(hentPerson.foedsel); + PdlFoedsel foedsel = (PdlFoedsel)getFirstActiveOrNull(hentPerson.foedsel); if (foedsel?.foedselsdato != null) { DateTime dob = foedsel.foedselsdato; // hack; Date lacks format person.INT_DateOfBirth__c = dob.format('yyyy-MM-dd'); @@ -361,24 +371,24 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess setDateOfBirth(person, hentPerson); // Navn - PdlNavn navn = (PdlNavn)getActiveOrNone(hentPerson.navn); + PdlNavn navn = (PdlNavn)getFirstActiveOrNull(hentPerson.navn); person.INT_FirstName__c = navn.fornavn ?? ''; person.INT_MiddleName__c = navn.mellomnavn ?? ''; person.INT_LastName__c = navn.etternavn ?? ''; // folkeregisterpersonstatus - person.INT_LegalStatus__c = ((PdlFolkeregisterpersonstatus)getActiveOrNone(hentPerson.folkeregisterpersonstatus))?.status; + person.INT_LegalStatus__c = ((PdlFolkeregisterpersonstatus)getFirstActiveOrNull(hentPerson.folkeregisterpersonstatus))?.status; // InnflytningTilNorge - PdlInnflyttingtilnorge innflytting = (PdlInnflyttingtilnorge)getActiveOrNone(hentPerson.innflyttingTilNorge); + PdlInnflyttingtilnorge innflytting = (PdlInnflyttingtilnorge)getFirstActiveOrNull(hentPerson.innflyttingTilNorge); person.INT_MovedFromCountry__c = getCountryIdFromIso(innflytting?.fraflyttingsland); person.INT_MovedFromPlace__c = innflytting?.fraflyttingsstedIUtlandet; // adressebeskyttelse person.INT_Confidential__c = clearanceLevel(getAllActive(hentPerson.adressebeskyttelse)); - // sikkerhetstiltak - person.INT_SecurityMeasures__c = JSON.serialize(kafkaPerson.hentPerson.sikkerhetstiltak); + // sikkerhetstiltak (serialized) + person.INT_SecurityMeasures__c = JSON.serialize(getAllActive(hentPerson.sikkerhetstiltak)); // adresse setAddress(person, kafkaPerson.hentPerson, gtPerson); @@ -387,25 +397,26 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess person.INT_Citizenships__c = createCitizenshipString(hentPerson.statsborgerskap); // sivilstand - if (hentPerson.sivilstand.size() > 0) { - person.INT_MaritalStatus__c = hentPerson.sivilstand[hentPerson.sivilstand.size() - 1].type.name(); - person.INT_MaritalStatusDate__c = hentPerson.sivilstand[hentPerson.sivilstand.size() - 1].gyldigFraOgMed; - person.INT_MaritalRelation__c = hentPerson.sivilstand[hentPerson.sivilstand.size() - 1].relatertVedSivilstand; - } + PdlSivilstand sivilstand = (PdlSivilstand)getFirstActiveOrNull(hentPerson.sivilstand); + person.INT_MaritalStatus__c = sivilstand?.type.name(); + person.INT_MaritalStatusDate__c = sivilstand?.gyldigFraOgMed; + person.INT_MaritalRelation__c = sivilstand?.relatertVedSivilstand; // kjoenn - if (hentPerson.kjoenn.size() > 0) { - person.INT_Sex__c = hentPerson.kjoenn[hentPerson.kjoenn.size() - 1].kjoenn.name(); - } + person.INT_Sex__c = ((PdlKjoenn)getFirstActiveOrNull(hentPerson.kjoenn))?.kjoenn.name(); - // doedsfall + // doedsfall. + // multiple results from multiple masters possible. + // no _historisk_ entries should occur, so no need to filter first. if (hentPerson.doedsfall.size() > 0) { person.INT_DateOfDeath__c = getBestDateOfDeath(hentPerson.doedsfall); person.INT_IsDeceased__c = true; //If we got any records return true even if we don't have a date. } - // telefonnummer - for (PdlTelefonnummer tlf : hentPerson.telefonnummer) { + // telefonnummer. get up to two. + PdlObject[] numbers = getAllActive(hentPerson.telefonnummer); + for (PdlObject tlfObj : numbers) { + PdlTelefonnummer tlf = (PdlTelefonnummer)tlfObj; if (tlf.prioritet == 1) { person.INT_Phone1__c = tlf.landskode + tlf.nummer; } @@ -415,30 +426,22 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } // utflyttingFraNorge - if (hentPerson.utflyttingFraNorge.size() > 0) { - person.INT_MovedToCountry__c = getCountryIdFromIso( - hentPerson.utflyttingFraNorge[hentPerson.utflyttingFraNorge.size() - 1].tilflyttingsland - ); - person.INT_MovedToPlace__c = hentPerson.utflyttingFraNorge[hentPerson.utflyttingFraNorge.size() - 1].tilflyttingsstedIUtlandet; - } + PdlUtflyttingfranorge emigration = (PdlUtflyttingfranorge)getFirstActiveOrNull(hentPerson.utflyttingFraNorge); + person.INT_MovedToCountry__c = getCountryIdFromIso(emigration?.tilflyttingsland); + person.INT_MovedToPlace__c = emigration?.tilflyttingsstedIUtlandet; - // talespraaktolk - // Misleading name, should have been called talespraaktolkbehov + // FKA talespraaktolk. (misleading name, should have been called + // talespraaktolkbehov.) // When non-null, person needs an interpreter, and the non-null value is // a list of the languages for which an interpreter is required. person.INT_SpokenLanguageIntepreter__c = interpreterLanguagesString(hentPerson.tilrettelagtKommunikasjon); - // fullmakt - person.INT_PowerOfAttorney__c = (hentPerson.fullmakt == null || - hentPerson.fullmakt.size() == 0) - ? null - : JSON.serialize(hentPerson.fullmakt); + // fullmakt (serialized) + person.INT_PowerOfAttorney__c = getSerializedActiveOrNull(hentPerson.fullmakt); // vergemaalEllerFremtidsfullmakt - person.INT_GuardianshipOrFuturePowerOfAttorney__c = (hentPerson.vergemaalEllerFremtidsfullmakt == null || - hentPerson.vergemaalEllerFremtidsfullmakt.size() == 0) - ? null - : JSON.serialize(hentPerson.vergemaalEllerFremtidsfullmakt); + person.INT_GuardianshipOrFuturePowerOfAttorney__c = getSerializedActiveOrNull( + hentPerson.vergemaalEllerFremtidsfullmakt); // Ensure that a System User is set as Owner if even if message processing is manually retried by an administrator user if (KafkaIntegrationCustomSetting.integrationUserId != null) { @@ -468,7 +471,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess private void setAddressFortroligOrUgradert(Person__c person, PdlHentperson hentPerson) { // bostedsadresser // assumption: vegadresse has first pri, then ukjentbosted... - PdlBostedsadresse bo = (PdlBostedsadresse)getActiveOrNone(hentPerson.bostedsadresse); + PdlBostedsadresse bo = (PdlBostedsadresse)getFirstActiveOrNull(hentPerson.bostedsadresse); if (bo?.vegadresse != null) { person.INT_ResidentialAddress__c = addressCreator( new List{ @@ -507,7 +510,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess // oppholdsadresser // assumption: vegadresse has first pri, then utenlandskAdresse, then ukjentbosted - PdlOppholdsadresse opphold = hentPerson.oppholdsadresse.size() > 0 ? hentPerson.oppholdsadresse[0] : null; + PdlOppholdsadresse opphold = (PdlOppholdsadresse)getFirstActiveOrNull(hentPerson.oppholdsadresse); if (opphold?.vegadresse != null) { person.INT_TemporaryAddress__c = addressCreator( new List{ @@ -605,7 +608,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess /** * Return the date of death - * @param deaths list for KafkaPerson2.Doedsfall + * @param deaths list deaths. _historisk_ is not relevant here. [0] * @return Date PDL-date if found, otherwise folkeregister-date, otherwise * null. */ @@ -629,16 +632,17 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * TODO: write test for multiple of these */ @TestVisible - private static String interpreterLanguagesString(PdlTilrettelagtkommunikasjon[] comms) { + private static String interpreterLanguagesString(PdlObject[] comms) { String[] interpreterLanguages = new List(); - if (comms == null || comms.size() == 0) { - return null; - } - for (PdlTilrettelagtkommunikasjon comm : comms) { + for (PdlObject commObj : comms) { + PdlTilrettelagtkommunikasjon comm = (PdlTilrettelagtkommunikasjon)commObj; if (comm.talespraaktolk != null) { interpreterLanguages.add(comm.talespraaktolk.spraak); } } + if (interpreterLanguages.size() == 0) { + return null; + } return String.join(interpreterLanguages, ';'); } From baaa56875af8badbaf9f7bad930d23e6fe54848d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 17 Apr 2024 18:31:53 +0200 Subject: [PATCH 110/159] remove shady reliance on ordering --- .../pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 09d493a6..082fc7c3 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -545,12 +545,11 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess /** * Sets the address, if appropriate. - * Appears to require that address protection has _already_ been applied - * to the person object. Seems dangerous. */ @TestVisible private void setAddress(Person__c person, PdlHentperson hentPerson, Person__c gtPerson) { - if (ADR_BESKYTTELSES_GRADERING.get(person.INT_Confidential__c) <= 2) { + String clearance = clearanceLevel(getAllActive(hentPerson.adressebeskyttelse)); + if (ADR_BESKYTTELSES_GRADERING.get(clearance) <= 2) { setAddressFortroligOrUgradert(person, hentPerson); setMunicipalityAndOrDistrict(person, gtPerson); } From a66436cb1b34a129ef626e1fdd73bd8acf24f44c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 19 Apr 2024 02:12:15 +0200 Subject: [PATCH 111/159] shorten a bit --- .../classes/KafkaPdlPersondokumentHandler.cls | 99 +++++++++---------- 1 file changed, 44 insertions(+), 55 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 082fc7c3..38474db3 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -351,6 +351,34 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } } + /** + * Sets death and optionally date of death. + * Multiple results from multiple masters possible. + * No _historisk_ entries should occur, so no need to filter first. + */ + private static void setDeath(Person__c person, PdlHentperson hentPerson) { + if (hentPerson.doedsfall.size() > 0) { + person.INT_DateOfDeath__c = getBestDateOfDeath(hentPerson.doedsfall); + person.INT_IsDeceased__c = true; //If we got any records return true even if we don't have a date. + } + } + + /** + * Sets up to two phone numbers. + */ + private static void setPhoneNumbers(Person__c person, PdlHentperson hentPerson) { + PdlObject[] numbers = getAllActive(hentPerson.telefonnummer); + for (PdlObject tlfObj : numbers) { + PdlTelefonnummer tlf = (PdlTelefonnummer)tlfObj; + if (tlf.prioritet == 1) { + person.INT_Phone1__c = tlf.landskode + tlf.nummer; + } + if (tlf.prioritet == 2) { + person.INT_Phone2__c = tlf.landskode + tlf.nummer; + } + } + } + /** * Transforms and map fields to Person__c from KafkaPerson3 * @param person New Person__c SObject record @@ -367,82 +395,39 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess setIdents(person, kafkaPerson); setNameField(person, hentIdenter); - // No longer required fields - setDateOfBirth(person, hentPerson); - - // Navn + // More or less direct mappings. grab the first non-historical field. PdlNavn navn = (PdlNavn)getFirstActiveOrNull(hentPerson.navn); person.INT_FirstName__c = navn.fornavn ?? ''; person.INT_MiddleName__c = navn.mellomnavn ?? ''; person.INT_LastName__c = navn.etternavn ?? ''; - - // folkeregisterpersonstatus person.INT_LegalStatus__c = ((PdlFolkeregisterpersonstatus)getFirstActiveOrNull(hentPerson.folkeregisterpersonstatus))?.status; - - // InnflytningTilNorge PdlInnflyttingtilnorge innflytting = (PdlInnflyttingtilnorge)getFirstActiveOrNull(hentPerson.innflyttingTilNorge); person.INT_MovedFromCountry__c = getCountryIdFromIso(innflytting?.fraflyttingsland); person.INT_MovedFromPlace__c = innflytting?.fraflyttingsstedIUtlandet; - - // adressebeskyttelse person.INT_Confidential__c = clearanceLevel(getAllActive(hentPerson.adressebeskyttelse)); - - // sikkerhetstiltak (serialized) - person.INT_SecurityMeasures__c = JSON.serialize(getAllActive(hentPerson.sikkerhetstiltak)); - - // adresse - setAddress(person, kafkaPerson.hentPerson, gtPerson); - - // statsborgerskap - person.INT_Citizenships__c = createCitizenshipString(hentPerson.statsborgerskap); - - // sivilstand PdlSivilstand sivilstand = (PdlSivilstand)getFirstActiveOrNull(hentPerson.sivilstand); person.INT_MaritalStatus__c = sivilstand?.type.name(); person.INT_MaritalStatusDate__c = sivilstand?.gyldigFraOgMed; person.INT_MaritalRelation__c = sivilstand?.relatertVedSivilstand; - - // kjoenn person.INT_Sex__c = ((PdlKjoenn)getFirstActiveOrNull(hentPerson.kjoenn))?.kjoenn.name(); - - // doedsfall. - // multiple results from multiple masters possible. - // no _historisk_ entries should occur, so no need to filter first. - if (hentPerson.doedsfall.size() > 0) { - person.INT_DateOfDeath__c = getBestDateOfDeath(hentPerson.doedsfall); - person.INT_IsDeceased__c = true; //If we got any records return true even if we don't have a date. - } - - // telefonnummer. get up to two. - PdlObject[] numbers = getAllActive(hentPerson.telefonnummer); - for (PdlObject tlfObj : numbers) { - PdlTelefonnummer tlf = (PdlTelefonnummer)tlfObj; - if (tlf.prioritet == 1) { - person.INT_Phone1__c = tlf.landskode + tlf.nummer; - } - if (tlf.prioritet == 2) { - person.INT_Phone2__c = tlf.landskode + tlf.nummer; - } - } - - // utflyttingFraNorge PdlUtflyttingfranorge emigration = (PdlUtflyttingfranorge)getFirstActiveOrNull(hentPerson.utflyttingFraNorge); person.INT_MovedToCountry__c = getCountryIdFromIso(emigration?.tilflyttingsland); person.INT_MovedToPlace__c = emigration?.tilflyttingsstedIUtlandet; - // FKA talespraaktolk. (misleading name, should have been called - // talespraaktolkbehov.) - // When non-null, person needs an interpreter, and the non-null value is - // a list of the languages for which an interpreter is required. - person.INT_SpokenLanguageIntepreter__c = interpreterLanguagesString(hentPerson.tilrettelagtKommunikasjon); - - // fullmakt (serialized) + // Serialized fields + person.INT_SecurityMeasures__c = JSON.serialize(getAllActive(hentPerson.sikkerhetstiltak)); person.INT_PowerOfAttorney__c = getSerializedActiveOrNull(hentPerson.fullmakt); - - // vergemaalEllerFremtidsfullmakt person.INT_GuardianshipOrFuturePowerOfAttorney__c = getSerializedActiveOrNull( hentPerson.vergemaalEllerFremtidsfullmakt); + // Fancy mappings + setDateOfBirth(person, hentPerson); + setAddress(person, kafkaPerson.hentPerson, gtPerson); + person.INT_Citizenships__c = createCitizenshipString(hentPerson.statsborgerskap); + person.INT_SpokenLanguageIntepreter__c = interpreterLanguagesString(hentPerson.tilrettelagtKommunikasjon); + setDeath(person, hentPerson); + setPhoneNumbers(person, hentPerson); + // Ensure that a System User is set as Owner if even if message processing is manually retried by an administrator user if (KafkaIntegrationCustomSetting.integrationUserId != null) { person.OwnerId = KafkaIntegrationCustomSetting.integrationUserId; @@ -612,7 +597,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * null. */ @TestVisible - private Date getBestDateOfDeath(List deaths) { + private static Date getBestDateOfDeath(List deaths) { Map dateAccordingTo = new Map(); for (PdlDoedsfall death : deaths) { dateAccordingTo.put(death.metadata.master.toUpperCase(), Date.valueOf(death.doedsdato)); @@ -626,6 +611,10 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess /** * Safely transform spoken language interpreter information into string * compatible with multipicklist-fields. + * FKA talespraaktolk. (misleading name, should have been called + * talespraaktolkbehov.) + * When non-null, person needs an interpreter, and the non-null value is + * a list of the languages for which an interpreter is required. * @param comms Collection of facilitated communication * @return null or strings joined with ';' * TODO: write test for multiple of these From fe8f4fe6c77f957498c41cb8bb48ce3a966fc6ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 19 Apr 2024 02:19:53 +0200 Subject: [PATCH 112/159] reorder, comment --- .../classes/KafkaPdlPersondokumentHandler.cls | 322 +++++++++--------- 1 file changed, 161 insertions(+), 161 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 38474db3..13ad0d6e 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -1,5 +1,7 @@ /** - * Yes, just a copy of KafkaPDLHandler2 for now. + * Handles messages from a filtered pdl-persondokument-{,tagged-}v1 topic. + * Should do what KafkaPDLHandler2 previously did to the messages posted by + * the intermediate nks-sf-pdl app. */ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMessageConsumer { @@ -51,110 +53,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } } - /** - * Process messages. Catch various exceptions and then warn or error (i.e. - * set CRM_Status__c on the KafkaMessage__c) according to some criteria - * which seem to be the following: - * - any PdlIdentException should be treated like an error - * - any other Exception is: - * - error, if person already exists - * - warning, if person doesn't exist - */ - public void processMessages(List messages) { - // map for storing potential gt info that already exists - Map gtFromActorId = new Map(); - // maps to be set only after successful person creation - Map personFromActorId = new Map(); - Map messageFromActorId = new Map(); - // If we have a message where the created date is older than last - // updated, set it to error so that we can investigate it. If we have a - // tombstone without a person in Salesforce, set it to processed. - // clobbers _messages_ in the sense that its CRM_Status__c may change. - checkLastUpdatedAndTombStones(messages); - // If we have INT_GT... fields already saved, we would like to keep them. - fetchGeografiskTilknytning(gtFromActorId, messages); - for (KafkaMessage__c msg : messages) { - // exclude the ones modified by checkLastUpdatedAndTombStones - if (msg.CRM_Status__c == KafkaMessageService.STATUS_PENDING) { - try { - Person__c person = createPersonRecord(msg, gtFromActorId.get(msg.CRM_Key__c)); - // if success, then: - personFromActorId.put(person.INT_ActorId__c, person); - messageFromActorId.put(person.INT_ActorId__c, msg); - msg.CRM_Status__c = KafkaMessageService.STATUS_PROCESSED; - } catch (PdlIdentException e) { - // big mistake. - String errorMsg = e.getTypeName() + ': ' + e.getMessage() + ' (' + e.getLineNumber() + ')'; - setMessageError(errorMsg, msg, KafkaMessageService.STATUS_ERROR); - logger.error( - 'Caught PdlIdentException when attempting to create Person__c:\n' + - e.getMessage() + - '\nKafka key reference: ' + - msg.CRM_Key__c, - null - ); - } catch (Exception e) { - // big mistake if person already exists, otherwise small - // mistake. - String errorMsg = e.getTypeName() + ': ' + e.getMessage() + ' (' + e.getLineNumber() + ')'; - setMessageError(errorMsg, msg); - if (msg.CRM_Status__c == KafkaMessageService.STATUS_ERROR) { - logger.error( - 'Caught unknown exception when attempting to create Person__c.\n' + - 'Kafka key reference: ' + - msg.CRM_Key__c, - null, - CRM_ApplicationDomain.domain.PDL - ); - } else if (msg.CRM_Status__c == KafkaMessageService.STATUS_WARNING) { - logger.warning( - 'Warning creating Person__c from PDL Kafka message. ' + - '\nKafka key reference: ' + - msg.CRM_Key__c, - null, - CRM_ApplicationDomain.domain.PDL - ); - } - } - } - } - List personList = new List(); - List messageList = new List(); - for (String actorId : personFromActorId.keySet()) { - personList.add(personFromActorId.get(actorId)); - messageList.add(messageFromActorId.get(actorId)); - } - // Errors from DML will set all messages to failed. - List urList = Database.upsert(personList, Person__c.INT_ActorId__c, false); - for (Integer i = 0; i < urList.size(); i++) { - if (false == urList[i].isSuccess()) { - String errorMsg = 'Upsert error:'; - for (Database.Error error : urList[i].getErrors()) { - errorMsg += ' * ' + error.getMessage(); - } - setMessageError(errorMsg, messageList[i]); - if (messageList[i].CRM_Status__c == KafkaMessageService.STATUS_ERROR) { - logger.error( - 'Error updating Person__c.' + - '\n Kafka key reference: ' + - messageList[i].CRM_Key__c, - null, - CRM_ApplicationDomain.domain.PDL - ); - } else if (messageList[i].CRM_Status__c == KafkaMessageService.STATUS_WARNING) { - logger.warning( - 'Warning updating Person__c.' + - '\n Kafka key reference: ' + - messageList[i].CRM_Key__c, - null, - CRM_ApplicationDomain.domain.PDL - ); - } - } - } - logger.publish(); - } - /** * Validates that the Kafka Message is not older than the last PDL Update on * the Person. @@ -379,62 +277,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } } - /** - * Transforms and map fields to Person__c from KafkaPerson3 - * @param person New Person__c SObject record - * @param kafkaPerson deserialized object representing a PersonDokument - * @return Person Account with initialized fields - */ - private Person__c mapFieldValues( - Person__c person, KafkaPerson3 kafkaPerson, Person__c gtPerson - ) { - KafkaPerson3.HentIdenter hentIdenter = kafkaPerson.hentIdenter; - PdlHentperson hentPerson = kafkaPerson.hentPerson; - - // Required fields - setIdents(person, kafkaPerson); - setNameField(person, hentIdenter); - - // More or less direct mappings. grab the first non-historical field. - PdlNavn navn = (PdlNavn)getFirstActiveOrNull(hentPerson.navn); - person.INT_FirstName__c = navn.fornavn ?? ''; - person.INT_MiddleName__c = navn.mellomnavn ?? ''; - person.INT_LastName__c = navn.etternavn ?? ''; - person.INT_LegalStatus__c = ((PdlFolkeregisterpersonstatus)getFirstActiveOrNull(hentPerson.folkeregisterpersonstatus))?.status; - PdlInnflyttingtilnorge innflytting = (PdlInnflyttingtilnorge)getFirstActiveOrNull(hentPerson.innflyttingTilNorge); - person.INT_MovedFromCountry__c = getCountryIdFromIso(innflytting?.fraflyttingsland); - person.INT_MovedFromPlace__c = innflytting?.fraflyttingsstedIUtlandet; - person.INT_Confidential__c = clearanceLevel(getAllActive(hentPerson.adressebeskyttelse)); - PdlSivilstand sivilstand = (PdlSivilstand)getFirstActiveOrNull(hentPerson.sivilstand); - person.INT_MaritalStatus__c = sivilstand?.type.name(); - person.INT_MaritalStatusDate__c = sivilstand?.gyldigFraOgMed; - person.INT_MaritalRelation__c = sivilstand?.relatertVedSivilstand; - person.INT_Sex__c = ((PdlKjoenn)getFirstActiveOrNull(hentPerson.kjoenn))?.kjoenn.name(); - PdlUtflyttingfranorge emigration = (PdlUtflyttingfranorge)getFirstActiveOrNull(hentPerson.utflyttingFraNorge); - person.INT_MovedToCountry__c = getCountryIdFromIso(emigration?.tilflyttingsland); - person.INT_MovedToPlace__c = emigration?.tilflyttingsstedIUtlandet; - - // Serialized fields - person.INT_SecurityMeasures__c = JSON.serialize(getAllActive(hentPerson.sikkerhetstiltak)); - person.INT_PowerOfAttorney__c = getSerializedActiveOrNull(hentPerson.fullmakt); - person.INT_GuardianshipOrFuturePowerOfAttorney__c = getSerializedActiveOrNull( - hentPerson.vergemaalEllerFremtidsfullmakt); - - // Fancy mappings - setDateOfBirth(person, hentPerson); - setAddress(person, kafkaPerson.hentPerson, gtPerson); - person.INT_Citizenships__c = createCitizenshipString(hentPerson.statsborgerskap); - person.INT_SpokenLanguageIntepreter__c = interpreterLanguagesString(hentPerson.tilrettelagtKommunikasjon); - setDeath(person, hentPerson); - setPhoneNumbers(person, hentPerson); - - // Ensure that a System User is set as Owner if even if message processing is manually retried by an administrator user - if (KafkaIntegrationCustomSetting.integrationUserId != null) { - person.OwnerId = KafkaIntegrationCustomSetting.integrationUserId; - } - return person; - } - /** * Create a readable string from a coordinate object. * Note: coordinates are currently useless, but PDL may implement them @@ -530,6 +372,9 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess /** * Sets the address, if appropriate. + * If the clearance level has increased, there should be an UDEFINERT + * message on the geografisk tilknytning topic that lets the GT handler + * clear whatever GT fields are set. */ @TestVisible private void setAddress(Person__c person, PdlHentperson hentPerson, Person__c gtPerson) { @@ -1005,6 +850,161 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess message.CRM_Status__c = status; } + /** + * Transforms and map fields to Person__c from KafkaPerson3 + * @param person New Person__c SObject record + * @param kafkaPerson deserialized object representing a PersonDokument + * @return Person Account with initialized fields + */ + private Person__c mapFieldValues( + Person__c person, KafkaPerson3 kafkaPerson, Person__c gtPerson + ) { + KafkaPerson3.HentIdenter hentIdenter = kafkaPerson.hentIdenter; + PdlHentperson hentPerson = kafkaPerson.hentPerson; + // Required fields + setIdents(person, kafkaPerson); + setNameField(person, hentIdenter); + // More or less direct mappings. grab the first non-historical field. + PdlNavn navn = (PdlNavn)getFirstActiveOrNull(hentPerson.navn); + person.INT_FirstName__c = navn.fornavn ?? ''; + person.INT_MiddleName__c = navn.mellomnavn ?? ''; + person.INT_LastName__c = navn.etternavn ?? ''; + person.INT_LegalStatus__c = ((PdlFolkeregisterpersonstatus)getFirstActiveOrNull(hentPerson.folkeregisterpersonstatus))?.status; + PdlInnflyttingtilnorge innflytting = (PdlInnflyttingtilnorge)getFirstActiveOrNull(hentPerson.innflyttingTilNorge); + person.INT_MovedFromCountry__c = getCountryIdFromIso(innflytting?.fraflyttingsland); + person.INT_MovedFromPlace__c = innflytting?.fraflyttingsstedIUtlandet; + person.INT_Confidential__c = clearanceLevel(getAllActive(hentPerson.adressebeskyttelse)); + PdlSivilstand sivilstand = (PdlSivilstand)getFirstActiveOrNull(hentPerson.sivilstand); + person.INT_MaritalStatus__c = sivilstand?.type.name(); + person.INT_MaritalStatusDate__c = sivilstand?.gyldigFraOgMed; + person.INT_MaritalRelation__c = sivilstand?.relatertVedSivilstand; + person.INT_Sex__c = ((PdlKjoenn)getFirstActiveOrNull(hentPerson.kjoenn))?.kjoenn.name(); + PdlUtflyttingfranorge emigration = (PdlUtflyttingfranorge)getFirstActiveOrNull(hentPerson.utflyttingFraNorge); + person.INT_MovedToCountry__c = getCountryIdFromIso(emigration?.tilflyttingsland); + person.INT_MovedToPlace__c = emigration?.tilflyttingsstedIUtlandet; + // Serialized fields + person.INT_SecurityMeasures__c = JSON.serialize(getAllActive(hentPerson.sikkerhetstiltak)); + person.INT_PowerOfAttorney__c = getSerializedActiveOrNull(hentPerson.fullmakt); + person.INT_GuardianshipOrFuturePowerOfAttorney__c = getSerializedActiveOrNull( + hentPerson.vergemaalEllerFremtidsfullmakt); + // Fancy mappings + setDateOfBirth(person, hentPerson); + setAddress(person, kafkaPerson.hentPerson, gtPerson); + person.INT_Citizenships__c = createCitizenshipString(hentPerson.statsborgerskap); + person.INT_SpokenLanguageIntepreter__c = interpreterLanguagesString(hentPerson.tilrettelagtKommunikasjon); + setDeath(person, hentPerson); + setPhoneNumbers(person, hentPerson); + // Ensure that a System User is set as Owner if even if message processing is manually retried by an administrator user + if (KafkaIntegrationCustomSetting.integrationUserId != null) { + person.OwnerId = KafkaIntegrationCustomSetting.integrationUserId; + } + return person; + } + + /** + * Process messages. Catch various exceptions and then warn or error (i.e. + * set CRM_Status__c on the KafkaMessage__c) according to some criteria + * which seem to be the following: + * - any PdlIdentException should be treated like an error + * - any other Exception is: + * - error, if person already exists + * - warning, if person doesn't exist + */ + public void processMessages(List messages) { + // map for storing potential gt info that already exists + Map gtFromActorId = new Map(); + // maps to be set only after successful person creation + Map personFromActorId = new Map(); + Map messageFromActorId = new Map(); + // If we have a message where the created date is older than last + // updated, set it to error so that we can investigate it. If we have a + // tombstone without a person in Salesforce, set it to processed. + // clobbers _messages_ in the sense that its CRM_Status__c may change. + checkLastUpdatedAndTombStones(messages); + // If we have INT_GT... fields already saved, we would like to keep them. + fetchGeografiskTilknytning(gtFromActorId, messages); + for (KafkaMessage__c msg : messages) { + // exclude the ones modified by checkLastUpdatedAndTombStones + if (msg.CRM_Status__c == KafkaMessageService.STATUS_PENDING) { + try { + Person__c person = createPersonRecord(msg, gtFromActorId.get(msg.CRM_Key__c)); + // if success, then: + personFromActorId.put(person.INT_ActorId__c, person); + messageFromActorId.put(person.INT_ActorId__c, msg); + msg.CRM_Status__c = KafkaMessageService.STATUS_PROCESSED; + } catch (PdlIdentException e) { + // big mistake. + String errorMsg = e.getTypeName() + ': ' + e.getMessage() + ' (' + e.getLineNumber() + ')'; + setMessageError(errorMsg, msg, KafkaMessageService.STATUS_ERROR); + logger.error( + 'Caught PdlIdentException when attempting to create Person__c:\n' + + e.getMessage() + + '\nKafka key reference: ' + + msg.CRM_Key__c, + null + ); + } catch (Exception e) { + // big mistake if person already exists, otherwise small + // mistake. + String errorMsg = e.getTypeName() + ': ' + e.getMessage() + ' (' + e.getLineNumber() + ')'; + setMessageError(errorMsg, msg); + if (msg.CRM_Status__c == KafkaMessageService.STATUS_ERROR) { + logger.error( + 'Caught unknown exception when attempting to create Person__c.\n' + + 'Kafka key reference: ' + + msg.CRM_Key__c, + null, + CRM_ApplicationDomain.domain.PDL + ); + } else if (msg.CRM_Status__c == KafkaMessageService.STATUS_WARNING) { + logger.warning( + 'Warning creating Person__c from PDL Kafka message. ' + + '\nKafka key reference: ' + + msg.CRM_Key__c, + null, + CRM_ApplicationDomain.domain.PDL + ); + } + } + } + } + List personList = new List(); + List messageList = new List(); + for (String actorId : personFromActorId.keySet()) { + personList.add(personFromActorId.get(actorId)); + messageList.add(messageFromActorId.get(actorId)); + } + // Errors from DML will set all messages to failed. + List urList = Database.upsert(personList, Person__c.INT_ActorId__c, false); + for (Integer i = 0; i < urList.size(); i++) { + if (false == urList[i].isSuccess()) { + String errorMsg = 'Upsert error:'; + for (Database.Error error : urList[i].getErrors()) { + errorMsg += ' * ' + error.getMessage(); + } + setMessageError(errorMsg, messageList[i]); + if (messageList[i].CRM_Status__c == KafkaMessageService.STATUS_ERROR) { + logger.error( + 'Error updating Person__c.' + + '\n Kafka key reference: ' + + messageList[i].CRM_Key__c, + null, + CRM_ApplicationDomain.domain.PDL + ); + } else if (messageList[i].CRM_Status__c == KafkaMessageService.STATUS_WARNING) { + logger.warning( + 'Warning updating Person__c.' + + '\n Kafka key reference: ' + + messageList[i].CRM_Key__c, + null, + CRM_ApplicationDomain.domain.PDL + ); + } + } + } + logger.publish(); + } + public class PdlMissingEntryException extends Exception { } From 7f84f0e6c402dbc01ec99de83c98cdfa79a22fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 19 Apr 2024 02:39:18 +0200 Subject: [PATCH 113/159] remove unused method getPersonLastUpdatedMap --- .../classes/KafkaPdlPersondokumentHandler.cls | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 13ad0d6e..1ab71f6c 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -146,18 +146,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } } - private Map getPersonLastUpdatedMap(List actorIds) { - Map lastUpdatedMap = new Map(); - for (Person__c p : [ - SELECT INT_ActorId__c, INT_LastUpdatedFromPDL__c - FROM Person__c - WHERE INT_ActorId__c IN :actorIds - ]) { - lastUpdatedMap.put(p.INT_ActorId__c, p.INT_LastUpdatedFromPDL__c); - } - return lastUpdatedMap; - } - /** * Orchestrate deserialization, transformation, and Person__c creation for * each KafkaMessage From 21848a3c29bb8502a2513d4771b6f879a6f473f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 19 Apr 2024 02:40:26 +0200 Subject: [PATCH 114/159] remove debug print --- force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 1 - 1 file changed, 1 deletion(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 1ab71f6c..100279d9 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -98,7 +98,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess updatedList.add(p.INT_LastUpdatedFromPDL__c); } for (Integer i = 0; i < personIdList.size(); i++) { - System.debug('for: ' + personIdList[i]); if (!personTombSet.contains(personIdList[i]) && !split.contains(personIdList[i])) { if (!updatedMap.containsKey(personIdList[i])) { //A Map with ident as a key and LastUpdate as a value for existing persons From 3613aedcc12e61a71c3d77a0741447750d90f080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 30 Apr 2024 15:06:22 +0200 Subject: [PATCH 115/159] factor out upsertion of new/modified persons --- force-app/pdl-handler/classes/KafkaPdlGtHandler.cls | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index e49bfada..47b79726 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -98,6 +98,12 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer return person; } + private void upsertResult(List persons) { + List urList = Database.upsert(persons, Person__c.INT_ActorId__c, false); + // TODO check for errors, set status to error if so + System.debug(JSON.serializepretty(urList)); + } + public void processMessages(List messages) { logger = new LoggerUtility('PDL'); List persons = new List(); @@ -113,9 +119,7 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer msg.CRM_Status__c = KafkaMessageService.STATUS_PROCESSED; } } - List urList = Database.upsert(persons, Person__c.INT_ActorId__c, false); - // TODO check for errors, set status to error if so - System.debug(JSON.serializepretty(urList)); + upsertResult(persons); logger.publish(); } From 8e01c9f16a404b2bb3389489605787579c41e555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Thu, 2 May 2024 16:43:37 +0200 Subject: [PATCH 116/159] instantiate logger immediately --- force-app/pdl-handler/classes/KafkaPdlGtHandler.cls | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index 47b79726..9e98bbce 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -5,7 +5,7 @@ */ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer { - private LoggerUtility logger; + private LoggerUtility logger = new LoggerUtility('PDL'); private void assignIdent(Person__c p, String s) { if(s.length() == 13) { @@ -105,7 +105,6 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer } public void processMessages(List messages) { - logger = new LoggerUtility('PDL'); List persons = new List(); for (KafkaMessage__c msg : messages) { if (msg.CRM_Status__c == KafkaMessageService.STATUS_PENDING) { From fe416de3620dace661b6d4ac5d8a6bcf78209e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Thu, 2 May 2024 17:00:32 +0200 Subject: [PATCH 117/159] add failing test for upsert fail --- .../pdl-handler/classes/KafkaPdlGtHandler.cls | 2 + .../classes/KafkaPdlGtHandlerTest.cls | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index 9e98bbce..bfc9b40c 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -89,6 +89,7 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer * @param message integration record inserted by the integration user * @return Initialized Person Account ready for DML */ + @TestVisible private Person__c createPersonRecord(KafkaMessage__c message) { String decodedValue = KafkaMessageUtils.base64ULSafeDecode(message.CRM_Value__c).toString(); KafkaPersonGT kafkaPerson = KafkaPersonGT.parse(decodedValue); @@ -98,6 +99,7 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer return person; } + @TestVisible private void upsertResult(List persons) { List urList = Database.upsert(persons, Person__c.INT_ActorId__c, false); // TODO check for errors, set status to error if so diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index 17d9b0f9..eab8cedb 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -334,4 +334,41 @@ private with sharing class KafkaPdlGtHandlerTest { Assert.isNull(guy.INT_MunicipalityNumber__c); Assert.isNull(guy.INT_RegionNumber__c); } + + /** + * Tests that the kafka message statuses on a batch of two are correct when + * the DML fails on one of them. + */ + @IsTest + static void testPartialUpsert() { + // two valid messages + KafkaMessage__c[] messages = new KafkaMessage__c[]{ + new KafkaMessage__c( + CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Key__c = '4398046511104', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","34359738368"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), + CRM_Status__c = KafkaMessageService.STATUS_PENDING), + new KafkaMessage__c( + CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Key__c = '8796093022208', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["8796093022208","34359738368"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), + CRM_Status__c = KafkaMessageService.STATUS_PENDING)}; + // persons with the same indices + Person__c[] persons = new Person__c[]{}; + KafkaPdlGtHandler handler = new KafkaPdlGtHandler(); + for (KafkaMessage__c msg : messages) { + Person__c p = handler.createPersonRecord(msg); + persons.add(p); + msg.CRM_Status__c = KafkaMessageService.STATUS_PROCESSED; + } + // mess up one of our persons by exceeding the max length of one of its + // fields. this will trigger a dml exception upon insertion, which + // will set the kafka message status to Error. + persons[0].INT_GTDistrictNumber__c = '1234567'; + Test.startTest(); + handler.upsertResult(persons); + Test.stopTest(); + Assert.areEqual(KafkaMessageService.STATUS_ERROR, messages[0].CRM_Status__c); + Assert.areEqual(KafkaMessageService.STATUS_PROCESSED, messages[1].CRM_Status__c); + } } From 5c1ce41ca85be9f01958d75915b784265c911ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 6 May 2024 10:21:25 +0200 Subject: [PATCH 118/159] minor --- .../classes/KafkaPdlPersondokumentHandler.cls | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 100279d9..38be8156 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -57,8 +57,8 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * Validates that the Kafka Message is not older than the last PDL Update on * the Person. * If a new person is a tombstone, mark it not to be imported. - * Tombstones are not explicitly named in the message key, but are described - * by an empty message value. + * Tombstones are not explicitly named in the message key, but are + * distinguished by a _null_ message value. * @param messages Set of Kafka Messages in scope * @return Deduplicated set of Kafka Message */ @@ -75,7 +75,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess for (KafkaMessage__c msg : messages) { String actorId = msg.CRM_Key__c; Boolean isTombstone = msg.CRM_Value__c == null; - // Lists of key values wich match order of kafka messages + // Lists of key values which match order of kafka messages idList.add(actorId); tombList.add(isTombstone); // A Set of idents with tombstones from kafka messages @@ -89,12 +89,12 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess WHERE INT_ActorId__c IN :idList ]) { if (p.INT_IsHasTombstone__c) { - //A Set of idents wich already has tombstones + // A Set of idents which already has tombstones personTombSet.add(p.INT_ActorId__c); } - //A List with ident for existing persons + // A List with ident for existing persons personIdList.add(p.INT_ActorId__c); - //A List of Update Datetime values (same order as personIdList) + // A List of Update Datetime values (same order as personIdList) updatedList.add(p.INT_LastUpdatedFromPDL__c); } for (Integer i = 0; i < personIdList.size(); i++) { @@ -114,7 +114,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess if (split.contains(idList[i])) { //when a few person records with same actor id exists setMessageError( - 'There exists more than one records for Id.(split/merge)', + 'There exists more than one record for Id. (Split/merge.)', messages[i], KafkaMessageService.STATUS_ERROR ); @@ -124,7 +124,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } else if (updatedMap.containsKey(idList[i]) && (messages[i].createdDate < updatedMap.get(idList[i]))) { //when person exists and has more recent update setMessageError( - 'Trying update a newer record. Skip update.', + 'Trying to update a newer record. Skip update.', messages[i], KafkaMessageService.STATUS_WARNING ); @@ -137,7 +137,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess ); } else if (!updatedMap.containsKey(idList[i]) && tombList[i]) { setMessageError( - 'Trying insert Tombstone. Skip insert.', + 'Trying to insert Tombstone. Skip insert.', messages[i], KafkaMessageService.STATUS_PROCESSED ); @@ -901,6 +901,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess // map for storing potential gt info that already exists Map gtFromActorId = new Map(); // maps to be set only after successful person creation + // (TODO: what if there are multiple messages with the same actor id?) Map personFromActorId = new Map(); Map messageFromActorId = new Map(); // If we have a message where the created date is older than last From 1ff5e3355622bb30d1bdde68db29944a1e3994fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 8 May 2024 15:22:31 +0200 Subject: [PATCH 119/159] set Error on kafka message upon person upsert fail --- .../pdl-handler/classes/KafkaPdlGtHandler.cls | 63 +++++++++++++++---- .../classes/KafkaPdlGtHandlerTest.cls | 2 +- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index bfc9b40c..6f3eeaaf 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -1,7 +1,7 @@ /** - * all the gt-related fields factored out from the previous implementation, - * KafkaPDLHandler2 , - * since they now arrive in separate kafka messages. + * all the geographic affiliation related fields factored out from the previous + * implementation, KafkaPDLHandler2 , since they now arrive on separate kafka + * topics. */ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer { @@ -70,13 +70,13 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer logger.info('Setting GT from district', null); setFieldsFromDistrict(person, gt); } else if (gt.gtType == 'KOMMUNE') { - logger.info('Setting GT from municipality', null); + logger.info('Setting GT from municipality, clearing district fields', null); setFieldsFromMunicipality(person, gt); } else if (gt.gtType == 'UDEFINERT') { - logger.info('Not setting GT from UDEFINERT', null); + logger.info('Not setting GT from UDEFINERT, clearing all GT fields', null); } else if (gt.gtType == 'UTLAND') { logger.info('GT from abroad, doing nothing.', null); - // TODO + // TODO? } else { logger.error('Not setting GT, unknown gtType.', null); } @@ -99,15 +99,54 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer return person; } + private void setMessageError(String errorMsg, KafkaMessage__c message, String status) { + message.CRM_ErrorMessage__c = errorMsg.mid(0, 255); + message.CRM_Status__c = status; + } + + /** + * Save our modified/new persons to the database. + * May clobber the kafka messages, as they have already been set to + * Processed, so set them to Error in case of failure. (Consider doing this + * the other way around.) + * @param persons Persons to upsert + * @param processedMessages references to the messages in the same order as _persons_ + */ @TestVisible - private void upsertResult(List persons) { + private void upsertResult( + List persons, + List processedMessages + ) { + // An error from DML will set only that message to failed, + // unless the error is caused by a "before insert" hook, + // in which case the entire batch will fail. List urList = Database.upsert(persons, Person__c.INT_ActorId__c, false); - // TODO check for errors, set status to error if so - System.debug(JSON.serializepretty(urList)); + for (Integer i = 0; i < urList.size(); i++) { + if (false == urList[i].isSuccess()) { + String errorMsg = 'Upsert error:'; + for (Database.Error error : urList[i].getErrors()) { + errorMsg += ' * ' + error.getMessage(); + } + setMessageError(errorMsg, processedMessages[i], KafkaMessageService.STATUS_ERROR); + logger.error( + 'Error updating Person__c.\n' + + 'Kafka key reference: ' + + processedMessages[i].CRM_Key__c, + null, + CRM_ApplicationDomain.domain.PDL + ); + } + } } + /** + * Handle the messages sent. + * Implements the IKafkaMessageConsumer interface. + */ public void processMessages(List messages) { - List persons = new List(); + // lists of persons created and their associated kafka messages + Person__c[] persons = new List(); + KafkaMessage__c[] processedMessages = new List(); for (KafkaMessage__c msg : messages) { if (msg.CRM_Status__c == KafkaMessageService.STATUS_PENDING) { Person__c p = createPersonRecord(msg); @@ -117,10 +156,12 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer p.OwnerId = KafkaIntegrationCustomSetting.integrationUserId; } persons.add(p); + processedMessages.add(msg); + // set to processed; to be changed if upsert fails msg.CRM_Status__c = KafkaMessageService.STATUS_PROCESSED; } } - upsertResult(persons); + upsertResult(persons, processedMessages); logger.publish(); } diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index eab8cedb..bbd94d29 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -366,7 +366,7 @@ private with sharing class KafkaPdlGtHandlerTest { // will set the kafka message status to Error. persons[0].INT_GTDistrictNumber__c = '1234567'; Test.startTest(); - handler.upsertResult(persons); + handler.upsertResult(persons, messages); Test.stopTest(); Assert.areEqual(KafkaMessageService.STATUS_ERROR, messages[0].CRM_Status__c); Assert.areEqual(KafkaMessageService.STATUS_PROCESSED, messages[1].CRM_Status__c); From 7b91f927f9ba432b7cf4432c638c0fc0cbc50e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 13 May 2024 10:35:09 +0200 Subject: [PATCH 120/159] add test for duplicate keys --- .../classes/KafkaPdlGtHandlerTest.cls | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index bbd94d29..a3fbcb14 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -371,4 +371,35 @@ private with sharing class KafkaPdlGtHandlerTest { Assert.areEqual(KafkaMessageService.STATUS_ERROR, messages[0].CRM_Status__c); Assert.areEqual(KafkaMessageService.STATUS_PROCESSED, messages[1].CRM_Status__c); } + + /** + * Tests that when two valid messages with the same key appear in the same + * batch, they are both processed, and the result is one person with the + * values sent in the last message. + */ + @IsTest + static void testFailedUpsert() { + // two different messages with the same key + KafkaMessage__c[] messages = new KafkaMessage__c[]{ + new KafkaMessage__c( + CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Key__c = '4398046511104', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","34359738368"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), + CRM_Status__c = KafkaMessageService.STATUS_PENDING), + new KafkaMessage__c( + CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Key__c = '4398046511104', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","34359738368"],"geografiskTilknytning":{"gtType":"KOMMUNE","gtKommune":"7776","gtBydel":null,"gtLand":null,"regel":"666"}}')), + CRM_Status__c = KafkaMessageService.STATUS_PENDING)}; + KafkaPdlGtHandler handler = new KafkaPdlGtHandler(); + Test.startTest(); + handler.processMessages(messages); + Test.stopTest(); + Assert.areEqual(KafkaMessageService.STATUS_PROCESSED, messages[0].CRM_Status__c); + Assert.areEqual(KafkaMessageService.STATUS_PROCESSED, messages[1].CRM_Status__c); + Person__c[] persons = [SELECT INT_DistrictNumber__c, INT_MunicipalityNumber__c from Person__c]; + Assert.areEqual(1, persons.size()); + Assert.areEqual('7776', persons[0].INT_MunicipalityNumber__c); + Assert.isNull(persons[0].INT_DistrictNumber__c); + } } From 3dd59be7eceb58c6362f62c4d36b4b165491b525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 13 May 2024 12:31:49 +0200 Subject: [PATCH 121/159] minor comments --- .../classes/KafkaPdlPersondokumentHandler.cls | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 38be8156..fe3c3a09 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -898,10 +898,12 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * - warning, if person doesn't exist */ public void processMessages(List messages) { - // map for storing potential gt info that already exists + // map for storing gt info if it already exists Map gtFromActorId = new Map(); - // maps to be set only after successful person creation - // (TODO: what if there are multiple messages with the same actor id?) + // maps to be set only after successful person creation. + // if multiple messages in the same batch share an actor id, they are + // guaranteed™ to be in the correct order, so simply process them in + // order and map the actor id to the latest message and created person. Map personFromActorId = new Map(); Map messageFromActorId = new Map(); // If we have a message where the created date is older than last @@ -956,13 +958,17 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } } } + // create person list for upsertion and message list with matching + // indices List personList = new List(); List messageList = new List(); for (String actorId : personFromActorId.keySet()) { personList.add(personFromActorId.get(actorId)); messageList.add(messageFromActorId.get(actorId)); } - // Errors from DML will set all messages to failed. + // An error from DML will set only that message to failed, + // unless the error is caused by a "before insert" hook, + // in which case the entire batch will fail. List urList = Database.upsert(personList, Person__c.INT_ActorId__c, false); for (Integer i = 0; i < urList.size(); i++) { if (false == urList[i].isSuccess()) { From 671a487b6ec12464e7c992938c85df875e1ddfde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 13 May 2024 12:45:18 +0200 Subject: [PATCH 122/159] pass test by only upserting latest message i.e. earlier messages are set to Processed, but not upserted. --- .../pdl-handler/classes/KafkaPdlGtHandler.cls | 32 ++++++++++++------- .../classes/KafkaPdlGtHandlerTest.cls | 2 +- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index 6f3eeaaf..2a57ca15 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -107,15 +107,15 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer /** * Save our modified/new persons to the database. * May clobber the kafka messages, as they have already been set to - * Processed, so set them to Error in case of failure. (Consider doing this - * the other way around.) + * Processed, so set them to Error on failure. (Consider doing this the + * other way around.) * @param persons Persons to upsert - * @param processedMessages references to the messages in the same order as _persons_ + * @param messages references to the messages in the same order as _persons_ */ @TestVisible private void upsertResult( List persons, - List processedMessages + List messages ) { // An error from DML will set only that message to failed, // unless the error is caused by a "before insert" hook, @@ -127,11 +127,11 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer for (Database.Error error : urList[i].getErrors()) { errorMsg += ' * ' + error.getMessage(); } - setMessageError(errorMsg, processedMessages[i], KafkaMessageService.STATUS_ERROR); + setMessageError(errorMsg, messages[i], KafkaMessageService.STATUS_ERROR); logger.error( 'Error updating Person__c.\n' + 'Kafka key reference: ' + - processedMessages[i].CRM_Key__c, + messages[i].CRM_Key__c, null, CRM_ApplicationDomain.domain.PDL ); @@ -144,9 +144,10 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer * Implements the IKafkaMessageConsumer interface. */ public void processMessages(List messages) { - // lists of persons created and their associated kafka messages - Person__c[] persons = new List(); - KafkaMessage__c[] processedMessages = new List(); + // see KafkaPdlPersondokumentHandler.processMessages for comments on + // these maps + Map personFromActorId = new Map(); + Map messageFromActorId = new Map(); for (KafkaMessage__c msg : messages) { if (msg.CRM_Status__c == KafkaMessageService.STATUS_PENDING) { Person__c p = createPersonRecord(msg); @@ -155,13 +156,20 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer if (KafkaIntegrationCustomSetting.integrationUserId != null) { p.OwnerId = KafkaIntegrationCustomSetting.integrationUserId; } - persons.add(p); - processedMessages.add(msg); + personFromActorId.put(msg.CRM_Key__c, p); + messageFromActorId.put(msg.CRM_Key__c, msg); // set to processed; to be changed if upsert fails msg.CRM_Status__c = KafkaMessageService.STATUS_PROCESSED; } } - upsertResult(persons, processedMessages); + // lists of persons to be upserted and their associated kafka messages + Person__c[] persons = new List(); + KafkaMessage__c[] finalMessages = new List(); + for (String actorId : personFromActorId.keySet()) { + persons.add(personFromActorId.get(actorId)); + finalMessages.add(messageFromActorId.get(actorId)); + } + upsertResult(persons, finalMessages); logger.publish(); } diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index a3fbcb14..dd7b33cd 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -378,7 +378,7 @@ private with sharing class KafkaPdlGtHandlerTest { * values sent in the last message. */ @IsTest - static void testFailedUpsert() { + static void testDuplicateKeys() { // two different messages with the same key KafkaMessage__c[] messages = new KafkaMessage__c[]{ new KafkaMessage__c( From 9ff6f6fb64ba61ad263ac9cb446dd0d04b4b3f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 13 May 2024 13:53:23 +0200 Subject: [PATCH 123/159] get rid of nonexistent domain PDL, instead use CRM --- force-app/pdl-handler/classes/KafkaPdlGtHandler.cls | 2 +- .../classes/KafkaPdlPersondokumentHandler.cls | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index 2a57ca15..b6fc432c 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -133,7 +133,7 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer 'Kafka key reference: ' + messages[i].CRM_Key__c, null, - CRM_ApplicationDomain.domain.PDL + CRM_ApplicationDomain.domain.CRM ); } } diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index fe3c3a09..5cfbcec5 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -586,7 +586,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess '\n ISO Code: ' + isoCode, null, - CRM_ApplicationDomain.domain.PDL + CRM_ApplicationDomain.domain.CRM ); } return null; @@ -944,7 +944,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess 'Kafka key reference: ' + msg.CRM_Key__c, null, - CRM_ApplicationDomain.domain.PDL + CRM_ApplicationDomain.domain.CRM ); } else if (msg.CRM_Status__c == KafkaMessageService.STATUS_WARNING) { logger.warning( @@ -952,7 +952,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess '\nKafka key reference: ' + msg.CRM_Key__c, null, - CRM_ApplicationDomain.domain.PDL + CRM_ApplicationDomain.domain.CRM ); } } @@ -983,7 +983,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess '\n Kafka key reference: ' + messageList[i].CRM_Key__c, null, - CRM_ApplicationDomain.domain.PDL + CRM_ApplicationDomain.domain.CRM ); } else if (messageList[i].CRM_Status__c == KafkaMessageService.STATUS_WARNING) { logger.warning( @@ -991,7 +991,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess '\n Kafka key reference: ' + messageList[i].CRM_Key__c, null, - CRM_ApplicationDomain.domain.PDL + CRM_ApplicationDomain.domain.CRM ); } } From 6eded53ee19e6d9b62cebeac54ce2f78e31e1834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 13 May 2024 15:26:55 +0200 Subject: [PATCH 124/159] remove some debug prints --- force-app/pdl-handler/classes/KafkaPdlGtHandler.cls | 2 ++ .../pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index b6fc432c..a8e380ff 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -67,6 +67,8 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer nullOutFields(person); PdlGeografiskTilknytning gt = kafkaPerson.geografiskTilknytning; if (gt.gtType == 'BYDEL') { + // TODO: figure out exactly what sort of granularity we want when + // logging branching logger.info('Setting GT from district', null); setFieldsFromDistrict(person, gt); } else if (gt.gtType == 'KOMMUNE') { diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index e751caf5..0eebed2b 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -602,10 +602,8 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { // Act System.Test.startTest(); insert kafkaMessages; - System.debug([SELECT Id, CRM_Topic__c, CRM_Key__c, CRM_ErrorMessage__c FROM KafkaMessage__c]); AsyncRequestSchedulable.enqueueAsyncJobs(); System.Test.stopTest(); - System.debug([SELECT Id, CRM_Topic__c, CRM_Key__c, CRM_ErrorMessage__c FROM KafkaMessage__c]); // Assert that 1 Person Account has been inserted Assert.areEqual(1, [SELECT COUNT() FROM Person__c]); // Assert that all Kafka Message records have been marked as processed From 0408357e39f621d90732b6c8743f20657d31b923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 13 May 2024 18:33:35 +0200 Subject: [PATCH 125/159] write test for handling dupes in pd topic, passes --- .../classes/KafkaPdlPersondokumentHandler.cls | 3 +- .../KafkaPdlPersondokumentHandlerTest.cls | 30 ++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 5cfbcec5..1215380b 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -934,8 +934,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess null ); } catch (Exception e) { - // big mistake if person already exists, otherwise small - // mistake. + // big mistake if person already exists, otherwise small mistake. String errorMsg = e.getTypeName() + ': ' + e.getMessage() + ' (' + e.getLineNumber() + ')'; setMessageError(errorMsg, msg); if (msg.CRM_Status__c == KafkaMessageService.STATUS_ERROR) { diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 0eebed2b..7a6c12da 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -644,7 +644,8 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { CRM_Value__c = (kafkaPerson == null ? null : EncodingUtil.base64Encode(Blob.valueOf(JSON.serialize(kafkaPerson)))), - CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1' + CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Status__c = KafkaMessageService.STATUS_PENDING ); return kafkaMessage; } @@ -1478,4 +1479,31 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('x=354424.0, y=6862099.0, z=0.0',person.INT_TemporaryCoordinates__c); Assert.isNull(person.INT_TemporaryCountryCode__c); } + + /** + * Tests that when two valid messages with the same key appear in the same + * batch, they are both processed, and the result is one person with the + * values sent in the last message. + */ + @IsTest + static void testDuplicateKeys() { + KafkaPerson3 jekyll = createBaseKafkaPerson('3138428376721', '25937424601'); + jekyll.hentPerson.navn[0].fornavn = 'HENRY'; + jekyll.hentPerson.navn[0].etternavn = 'JEKYLL'; + KafkaPerson3 hyde = createBaseKafkaPerson('3138428376721', '25937424601'); + hyde.hentPerson.navn[0].etternavn = 'HYDE'; + KafkaMessage__c[] messages = new KafkaMessage__c[]{ + createKafkaMessage('3138428376721', jekyll), + createKafkaMessage('3138428376721', hyde)}; + KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); + Test.startTest(); + handler.processMessages(messages); + Test.stopTest(); + Assert.areEqual(KafkaMessageService.STATUS_PROCESSED, messages[0].CRM_Status__c); + Assert.areEqual(KafkaMessageService.STATUS_PROCESSED, messages[1].CRM_Status__c); + Person__c[] persons = [SELECT INT_FirstName__c, INT_LastName__c from Person__c]; + Assert.areEqual(1, persons.size()); + Assert.areEqual('HYDE', persons[0].INT_LastName__c); + Assert.isNull(persons[0].INT_FirstName__c); + } } From e2cc8f33290392c2f32a3367d27038d092ccaa58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 14 May 2024 15:12:17 +0200 Subject: [PATCH 126/159] minor --- force-app/pdl-handler/classes/KafkaPdlGtHandler.cls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index a8e380ff..885a15a9 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -124,7 +124,7 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer // in which case the entire batch will fail. List urList = Database.upsert(persons, Person__c.INT_ActorId__c, false); for (Integer i = 0; i < urList.size(); i++) { - if (false == urList[i].isSuccess()) { + if (!urList[i].isSuccess()) { String errorMsg = 'Upsert error:'; for (Database.Error error : urList[i].getErrors()) { errorMsg += ' * ' + error.getMessage(); From 5660179dc380aa6609c8985aa72ed693721946df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 15 May 2024 16:12:39 +0200 Subject: [PATCH 127/159] rename handler bindings, move test for both pdl+gt --- .../classes/KafkaPdlGtHandlerTest.cls | 39 +--- .../classes/KafkaPdlPdAndGtHandlersTest.cls | 170 ++++++++++++++++++ .../KafkaPdlPdAndGtHandlersTest.cls-meta.xml | 5 + ...nding.PdlGeografiskTilknytning.md-meta.xml | 2 +- ...ding.PdlPersondokumentHandler.md-meta.xml} | 2 +- 5 files changed, 178 insertions(+), 40 deletions(-) create mode 100644 force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls create mode 100644 force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls-meta.xml rename force-app/pdl-handler/customMetadata/{KafkaMessageHandlerBinding.PDLPersonHandler3.md-meta.xml => KafkaMessageHandlerBinding.PdlPersondokumentHandler.md-meta.xml} (95%) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index dd7b33cd..ccdac54d 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -48,8 +48,7 @@ private with sharing class KafkaPdlGtHandlerTest { } /** - * Initializes KafkaPerson3 as in KafkaPdlPersondokumentHandlerTest and - * creates and inserts a Person based on him. + * Initializes KafkaPerson3 as in KafkaPdlPersondokumentHandlerTest */ private static KafkaPerson3 createBaseKafkaPerson(String actorId) { KafkaPerson3 kp = new KafkaPerson3(); @@ -236,42 +235,6 @@ private with sharing class KafkaPdlGtHandlerTest { } } - /** - * Tests that updating the person document does not clear the address - * information fetched from the geographical affiliation, which should have - * a higher priority. - */ - @IsTest - static void setPersonDocAfterGt() { - Person__c[] people; - String sandvika; - // Basic person - createAndInsertBaseKafkaPerson('4398046511104', '68719476736'); - Test.startTest(); - // Set GT - insert new KafkaMessage__c( - CRM_Topic__c = 'pdl.geografisktilknytning-v1', - CRM_Key__c = '4398046511104', - CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), - CRM_Status__c = KafkaMessageService.STATUS_PENDING); - handleMessages(); - people = [SELECT INT_MunicipalityNumber__c from Person__c]; - Assert.areEqual(1, people.size()); - sandvika = people[0].INT_MunicipalityNumber__c; - Assert.areEqual('1337', sandvika); - // Minimal update to person that shouldn't affect address - insert new KafkaMessage__c( - CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', - CRM_Key__c = '4398046511104', - CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"hentPerson":{"adressebeskyttelse":[],"bostedsadresse":[{"angittFlyttedato":"1972-09-26","gyldigFraOgMed":"1972-09-26T00:00:00","gyldigTilOgMed":null,"coAdressenavn":null,"vegadresse":{"matrikkelId":330462890,"husnummer":"54","husbokstav":null,"bruksenhetsnummer":null,"adressenavn":"Tromøy kirkevei","kommunenummer":"4203","tilleggsnavn":null,"postnummer":"4818","bydelsnummer":null,"koordinater":{"x":489639.3,"y":6478898.8,"z":null}},"matrikkeladresse":null,"ukjentBosted":null,"utenlandskAdresse":null,"folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:39.83","gyldighetstidspunkt":"1972-09-26T00:00:00","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"582d32a7-f923-467a-9cd6-17976f6727d2","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:39.83","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"deltBosted":[],"doedfoedtBarn":[],"doedsfall":[],"foedsel":[],"folkeregisteridentifikator":[],"folkeregisterpersonstatus":[],"forelderBarnRelasjon":[],"foreldreansvar":[],"fullmakt":[],"identitetsgrunnlag":[],"innflyttingTilNorge":[],"kjoenn":[],"kontaktadresse":[],"kontaktinformasjonForDoedsbo":[],"navn":[{"etternavn":"FORTSATTSEN"}],"opphold":[],"oppholdsadresse":[],"sikkerhetstiltak":[],"sivilstand":[],"statsborgerskap":[],"telefonnummer":[],"tilrettelagtKommunikasjon":[],"utenlandskIdentifikasjonsnummer":[],"utflyttingFraNorge":[],"vergemaalEllerFremtidsfullmakt":[]},"hentIdenter":{"identer":[{"ident":"68719476736","historisk":false,"gruppe":"FOLKEREGISTERIDENT","metadata":null,"folkeregistermetadata":null},{"ident":"4398046511104","historisk":false,"gruppe":"AKTORID","metadata":null,"folkeregistermetadata":null}]}}')), - CRM_Status__c = KafkaMessageService.STATUS_PENDING); - handleMessages(); - people = [SELECT INT_MunicipalityNumber__c from Person__c]; - Assert.areEqual(1, people.size()); - sandvika = people[0].INT_MunicipalityNumber__c; - Assert.areEqual('1337', sandvika); - } - /** * Tests that nothing remains of the old GT when inserting a new GT with * lower precision. diff --git a/force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls b/force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls new file mode 100644 index 00000000..94248dbd --- /dev/null +++ b/force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls @@ -0,0 +1,170 @@ +/** + * Tests to ensure that KafkaPdlGtHandler and KafkaPdlPersondokumentHandler are + * playing together nicely. + */ +@IsTest +private with sharing class KafkaPdlPdAndGtHandlersTest { + + private static String GT_TOPIC = KafkaMessageHandlerBinding__mdt.getInstance('PdlGeografiskTilknytning').Topic__c; + private static String PD_TOPIC = KafkaMessageHandlerBinding__mdt.getInstance('PdlPersondokumentHandler').Topic__c; + + /** + * Sends kafka messages. like KafkaMessageAsyncJob but without the async + */ + private static void handleMessages() { + new KafkaMessageService( + [SELECT Id, CreatedDate, CRM_Topic__c, CRM_Key__c, CRM_Value__c FROM KafkaMessage__c WHERE CRM_Status__c = :KafkaMessageService.STATUS_PENDING] + ).handleMessages(); + } + + /** + * Create a message for inserting a person document. + * See KafkaPdlPersondokumentHandlerTest for more information. + * Explicitly set status; which would otherwise only get called when using + * KafkaMessageService (i.e. upon insert). + */ + private static KafkaMessage__c createPersonDocumentMessage( + String aktorId, + KafkaPerson3 kafkaPerson + ) { + KafkaMessage__c kafkaMessage = new KafkaMessage__c( + CRM_Key__c = aktorId, + CRM_Value__c = (kafkaPerson == null ? + null : + EncodingUtil.base64Encode(Blob.valueOf(JSON.serialize(kafkaPerson)))), + CRM_Topic__c = PD_TOPIC, + CRM_Status__c = KafkaMessageService.STATUS_PENDING + ); + return kafkaMessage; + } + + /** + * Inserts kafka person into the database + */ + private static void insertBaseKafkaPerson(String aktorId, KafkaPerson3 kp) { + KafkaMessage__c[] messages = new List{ + createPersonDocumentMessage(aktorId, kp) + }; + KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); + handler.processMessages(messages); // don't bother inserting the message + } + + /** + * Initializes KafkaPerson3 as in KafkaPdlPersondokumentHandlerTest + */ + private static KafkaPerson3 createBaseKafkaPerson(String actorId) { + KafkaPerson3 kp = new KafkaPerson3(); + kp.hentIdenter = new KafkaPerson3.HentIdenter(); + kp.hentIdenter.identer = new List(); + kp.hentPerson = new PdlHentperson(); + // just initialise all the lists. + kp.hentPerson.adressebeskyttelse = new List(); + kp.hentPerson.bostedsadresse = new List(); + kp.hentPerson.deltBosted = new List(); + kp.hentPerson.doedfoedtBarn = new List(); + kp.hentPerson.doedsfall = new List(); + kp.hentPerson.foedsel = new List(); + kp.hentPerson.folkeregisteridentifikator = new List(); + kp.hentPerson.folkeregisterpersonstatus = new List(); + kp.hentPerson.forelderBarnRelasjon = new List(); + kp.hentPerson.foreldreansvar = new List(); + kp.hentPerson.fullmakt = new List(); + kp.hentPerson.identitetsgrunnlag = new List(); + kp.hentPerson.innflyttingTilNorge = new List(); + kp.hentPerson.kjoenn = new List(); + kp.hentPerson.kontaktadresse = new List(); + kp.hentPerson.kontaktinformasjonForDoedsbo = new List(); + kp.hentPerson.navn = new List(); + kp.hentPerson.opphold = new List(); + kp.hentPerson.oppholdsadresse = new List(); + kp.hentPerson.sikkerhetstiltak = new List(); + kp.hentPerson.sivilstand = new List(); + kp.hentPerson.statsborgerskap = new List(); + kp.hentPerson.telefonnummer = new List(); + kp.hentPerson.tilrettelagtKommunikasjon = new List(); + kp.hentPerson.utenlandskIdentifikasjonsnummer = new List(); + kp.hentPerson.utflyttingFraNorge = new List(); + kp.hentPerson.vergemaalEllerFremtidsfullmakt = new List(); + // Default values + // Ident + kp.hentIdenter.identer.add(new PDL_IdentInformasjon()); + kp.hentIdenter.identer[0].gruppe = PDL_IdentGruppe.AKTORID; + kp.hentIdenter.identer[0].historisk = false; + kp.hentIdenter.identer[0].ident = actorId; + // Person status + kp.hentPerson.folkeregisterpersonstatus.add(new PdlFolkeregisterpersonstatus()); + kp.hentPerson.folkeregisterpersonstatus[0].status = 'bosatt'; + // Name + kp.hentPerson.navn.add(new PdlNavn()); + kp.hentPerson.navn[0].etternavn = 'TRESTRESEN'; + kp.hentPerson.adressebeskyttelse.add(new PdlAdressebeskyttelse()); + kp.hentPerson.adressebeskyttelse[0].gradering = PDL_AdressebeskyttelseGradering.UGRADERT; + return kp; + } + + /** + * Calls createBaseKafkaPerson(String), and adds a folkeregisterident + */ + private static KafkaPerson3 createBaseKafkaPerson(String actorId, String fregId) { + KafkaPerson3 kp = createBaseKafkaPerson(actorId); + kp.hentIdenter.identer.add(new PDL_IdentInformasjon()); + Integer i = kp.hentIdenter.identer.size() - 1; + kp.hentIdenter.identer[i].ident = fregId; + kp.hentIdenter.identer[i].historisk = false; + kp.hentIdenter.identer[i].gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; + return kp; + } + + /** + * Initializes KafkaPerson3 as in KafkaPdlPersondokumentHandlerTest and + * creates and inserts a Person based on him. + */ + private static void createAndInsertBaseKafkaPerson(String actorId) { + KafkaPerson3 kp = createBaseKafkaPerson(actorId); + insertBaseKafkaPerson(actorId, kp); + } + + /** + * As the above, but also includes folkeregisterident. + */ + private static void createAndInsertBaseKafkaPerson(String actorId, String fregId) { + KafkaPerson3 kp = createBaseKafkaPerson(actorId, fregId); + insertBaseKafkaPerson(actorId, kp); + } + + /** + * Tests that updating the person document does not clear the address + * information fetched from the geographical affiliation, which should have + * a higher priority. + */ + @IsTest + static void setPersonDocAfterGt() { + Person__c[] people; + String sandvika; + // Basic person + createAndInsertBaseKafkaPerson('4398046511104', '68719476736'); + Test.startTest(); + // Set GT + insert new KafkaMessage__c( + CRM_Topic__c = GT_TOPIC, + CRM_Key__c = '4398046511104', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), + CRM_Status__c = KafkaMessageService.STATUS_PENDING); + handleMessages(); + people = [SELECT INT_MunicipalityNumber__c from Person__c]; + Assert.areEqual(1, people.size()); + sandvika = people[0].INT_MunicipalityNumber__c; + Assert.areEqual('1337', sandvika); + // Minimal update to person that shouldn't affect address + insert new KafkaMessage__c( + CRM_Topic__c = PD_TOPIC, + CRM_Key__c = '4398046511104', + CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"hentPerson":{"adressebeskyttelse":[],"bostedsadresse":[{"angittFlyttedato":"1972-09-26","gyldigFraOgMed":"1972-09-26T00:00:00","gyldigTilOgMed":null,"coAdressenavn":null,"vegadresse":{"matrikkelId":330462890,"husnummer":"54","husbokstav":null,"bruksenhetsnummer":null,"adressenavn":"Tromøy kirkevei","kommunenummer":"4203","tilleggsnavn":null,"postnummer":"4818","bydelsnummer":null,"koordinater":{"x":489639.3,"y":6478898.8,"z":null}},"matrikkeladresse":null,"ukjentBosted":null,"utenlandskAdresse":null,"folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:39.83","gyldighetstidspunkt":"1972-09-26T00:00:00","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"582d32a7-f923-467a-9cd6-17976f6727d2","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:39.83","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"deltBosted":[],"doedfoedtBarn":[],"doedsfall":[],"foedsel":[],"folkeregisteridentifikator":[],"folkeregisterpersonstatus":[],"forelderBarnRelasjon":[],"foreldreansvar":[],"fullmakt":[],"identitetsgrunnlag":[],"innflyttingTilNorge":[],"kjoenn":[],"kontaktadresse":[],"kontaktinformasjonForDoedsbo":[],"navn":[{"etternavn":"FORTSATTSEN"}],"opphold":[],"oppholdsadresse":[],"sikkerhetstiltak":[],"sivilstand":[],"statsborgerskap":[],"telefonnummer":[],"tilrettelagtKommunikasjon":[],"utenlandskIdentifikasjonsnummer":[],"utflyttingFraNorge":[],"vergemaalEllerFremtidsfullmakt":[]},"hentIdenter":{"identer":[{"ident":"68719476736","historisk":false,"gruppe":"FOLKEREGISTERIDENT","metadata":null,"folkeregistermetadata":null},{"ident":"4398046511104","historisk":false,"gruppe":"AKTORID","metadata":null,"folkeregistermetadata":null}]}}')), + CRM_Status__c = KafkaMessageService.STATUS_PENDING); + handleMessages(); + people = [SELECT INT_MunicipalityNumber__c from Person__c]; + Assert.areEqual(1, people.size()); + sandvika = people[0].INT_MunicipalityNumber__c; + Assert.areEqual('1337', sandvika); + } +} diff --git a/force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls-meta.xml b/force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlGeografiskTilknytning.md-meta.xml b/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlGeografiskTilknytning.md-meta.xml index 54e0b078..bdba7f31 100644 --- a/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlGeografiskTilknytning.md-meta.xml +++ b/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlGeografiskTilknytning.md-meta.xml @@ -4,7 +4,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" > - + false ApexClass__c diff --git a/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PDLPersonHandler3.md-meta.xml b/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlPersondokumentHandler.md-meta.xml similarity index 95% rename from force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PDLPersonHandler3.md-meta.xml rename to force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlPersondokumentHandler.md-meta.xml index 6b15f2ef..361bc6b3 100644 --- a/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PDLPersonHandler3.md-meta.xml +++ b/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlPersondokumentHandler.md-meta.xml @@ -1,6 +1,6 @@ - + false ApexClass__c From 968dd706d971b4d80617e197c01fb796eee2952d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 15 May 2024 17:33:40 +0200 Subject: [PATCH 128/159] get topics from metadata instead of hardcoding --- .../pdl-handler/classes/KafkaPdlGtHandler.cls | 2 ++ .../classes/KafkaPdlGtHandlerTest.cls | 26 +++++++------- .../classes/KafkaPdlPdAndGtHandlersTest.cls | 9 ++--- .../classes/KafkaPdlPersondokumentHandler.cls | 2 ++ .../KafkaPdlPersondokumentHandlerTest.cls | 36 +++++++++---------- 5 files changed, 38 insertions(+), 37 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index 885a15a9..c378a78e 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -5,6 +5,8 @@ */ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer { + public static String GT_TOPIC = KafkaMessageHandlerBinding__mdt.getInstance('PdlGeografiskTilknytning').Topic__c; + private LoggerUtility logger = new LoggerUtility('PDL'); private void assignIdent(Person__c p, String s) { diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index ccdac54d..39a10956 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -30,7 +30,7 @@ private with sharing class KafkaPdlGtHandlerTest { CRM_Value__c = (kafkaPerson == null ? null : EncodingUtil.base64Encode(Blob.valueOf(JSON.serialize(kafkaPerson)))), - CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC, CRM_Status__c = KafkaMessageService.STATUS_PENDING ); return kafkaMessage; @@ -138,7 +138,7 @@ private with sharing class KafkaPdlGtHandlerTest { List kafkaMessages = new List(); kafkaMessages.add( new KafkaMessage__c( - CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Topic__c = KafkaPdlGtHandler.GT_TOPIC, CRM_Key__c = '1017419408436', CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["1017419408436","74194084361"],"geografiskTilknytning":{"gtType":"KOMMUNE","gtKommune":"1337","gtBydel":null,"gtLand":null,"regel":"2"}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING @@ -177,7 +177,7 @@ private with sharing class KafkaPdlGtHandlerTest { List kafkaMessages = new List(); kafkaMessages.add( new KafkaMessage__c( - CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Topic__c = KafkaPdlGtHandler.GT_TOPIC, CRM_Key__c = '4398046511104', CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"KOMMUNE","gtKommune":"1337","gtBydel":null,"gtLand":null,"regel":"2"}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING @@ -206,12 +206,12 @@ private with sharing class KafkaPdlGtHandlerTest { Test.startTest(); handler.processMessages(new List{ new KafkaMessage__c( - CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Topic__c = KafkaPdlGtHandler.GT_TOPIC, CRM_Key__c = '4398046511104', CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING), new KafkaMessage__c( - CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Topic__c = KafkaPdlGtHandler.GT_TOPIC, CRM_Key__c = '2541865828329', CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["2541865828329","10460353203"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING) @@ -244,7 +244,7 @@ private with sharing class KafkaPdlGtHandlerTest { Person__c guy; // Give our guy the highest precision (district) insert new KafkaMessage__c( - CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Topic__c = KafkaPdlGtHandler.GT_TOPIC, CRM_Key__c = '4398046511104', CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING); @@ -254,7 +254,7 @@ private with sharing class KafkaPdlGtHandlerTest { Assert.areEqual('133769', guy.INT_GTDistrictNumber__c); Assert.areEqual('133769', guy.INT_DistrictNumber__c); insert new KafkaMessage__c( - CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Topic__c = KafkaPdlGtHandler.GT_TOPIC, CRM_Key__c = '4398046511104', CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"KOMMUNE","gtKommune":"2024","gtBydel":null,"gtLand":null,"regel":"666"}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING); @@ -275,7 +275,7 @@ private with sharing class KafkaPdlGtHandlerTest { Person__c guy; // Give our guy the highest precision (district) insert new KafkaMessage__c( - CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Topic__c = KafkaPdlGtHandler.GT_TOPIC, CRM_Key__c = '4398046511104', CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING); @@ -283,7 +283,7 @@ private with sharing class KafkaPdlGtHandlerTest { guy = [SELECT INT_GTDistrictNumber__c, INT_DistrictNumber__c, INT_MunicipalityNumber__c from Person__c][0]; Assert.areEqual('1337', guy.INT_MunicipalityNumber__c); insert new KafkaMessage__c( - CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Topic__c = KafkaPdlGtHandler.GT_TOPIC, CRM_Key__c = '4398046511104', CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"UDEFINERT","gtKommune":null,"gtBydel":null,"gtLand":null,"regel":"666"}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING); @@ -307,12 +307,12 @@ private with sharing class KafkaPdlGtHandlerTest { // two valid messages KafkaMessage__c[] messages = new KafkaMessage__c[]{ new KafkaMessage__c( - CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Topic__c = KafkaPdlGtHandler.GT_TOPIC, CRM_Key__c = '4398046511104', CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","34359738368"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING), new KafkaMessage__c( - CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Topic__c = KafkaPdlGtHandler.GT_TOPIC, CRM_Key__c = '8796093022208', CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["8796093022208","34359738368"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING)}; @@ -345,12 +345,12 @@ private with sharing class KafkaPdlGtHandlerTest { // two different messages with the same key KafkaMessage__c[] messages = new KafkaMessage__c[]{ new KafkaMessage__c( - CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Topic__c = KafkaPdlGtHandler.GT_TOPIC, CRM_Key__c = '4398046511104', CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","34359738368"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING), new KafkaMessage__c( - CRM_Topic__c = 'pdl.geografisktilknytning-v1', + CRM_Topic__c = KafkaPdlGtHandler.GT_TOPIC, CRM_Key__c = '4398046511104', CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","34359738368"],"geografiskTilknytning":{"gtType":"KOMMUNE","gtKommune":"7776","gtBydel":null,"gtLand":null,"regel":"666"}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING)}; diff --git a/force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls b/force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls index 94248dbd..bd103397 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls @@ -5,9 +5,6 @@ @IsTest private with sharing class KafkaPdlPdAndGtHandlersTest { - private static String GT_TOPIC = KafkaMessageHandlerBinding__mdt.getInstance('PdlGeografiskTilknytning').Topic__c; - private static String PD_TOPIC = KafkaMessageHandlerBinding__mdt.getInstance('PdlPersondokumentHandler').Topic__c; - /** * Sends kafka messages. like KafkaMessageAsyncJob but without the async */ @@ -32,7 +29,7 @@ private with sharing class KafkaPdlPdAndGtHandlersTest { CRM_Value__c = (kafkaPerson == null ? null : EncodingUtil.base64Encode(Blob.valueOf(JSON.serialize(kafkaPerson)))), - CRM_Topic__c = PD_TOPIC, + CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC, CRM_Status__c = KafkaMessageService.STATUS_PENDING ); return kafkaMessage; @@ -146,7 +143,7 @@ private with sharing class KafkaPdlPdAndGtHandlersTest { Test.startTest(); // Set GT insert new KafkaMessage__c( - CRM_Topic__c = GT_TOPIC, + CRM_Topic__c = KafkaPdlGtHandler.GT_TOPIC, CRM_Key__c = '4398046511104', CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING); @@ -157,7 +154,7 @@ private with sharing class KafkaPdlPdAndGtHandlersTest { Assert.areEqual('1337', sandvika); // Minimal update to person that shouldn't affect address insert new KafkaMessage__c( - CRM_Topic__c = PD_TOPIC, + CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC, CRM_Key__c = '4398046511104', CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"hentPerson":{"adressebeskyttelse":[],"bostedsadresse":[{"angittFlyttedato":"1972-09-26","gyldigFraOgMed":"1972-09-26T00:00:00","gyldigTilOgMed":null,"coAdressenavn":null,"vegadresse":{"matrikkelId":330462890,"husnummer":"54","husbokstav":null,"bruksenhetsnummer":null,"adressenavn":"Tromøy kirkevei","kommunenummer":"4203","tilleggsnavn":null,"postnummer":"4818","bydelsnummer":null,"koordinater":{"x":489639.3,"y":6478898.8,"z":null}},"matrikkeladresse":null,"ukjentBosted":null,"utenlandskAdresse":null,"folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:39.83","gyldighetstidspunkt":"1972-09-26T00:00:00","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"582d32a7-f923-467a-9cd6-17976f6727d2","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:39.83","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"deltBosted":[],"doedfoedtBarn":[],"doedsfall":[],"foedsel":[],"folkeregisteridentifikator":[],"folkeregisterpersonstatus":[],"forelderBarnRelasjon":[],"foreldreansvar":[],"fullmakt":[],"identitetsgrunnlag":[],"innflyttingTilNorge":[],"kjoenn":[],"kontaktadresse":[],"kontaktinformasjonForDoedsbo":[],"navn":[{"etternavn":"FORTSATTSEN"}],"opphold":[],"oppholdsadresse":[],"sikkerhetstiltak":[],"sivilstand":[],"statsborgerskap":[],"telefonnummer":[],"tilrettelagtKommunikasjon":[],"utenlandskIdentifikasjonsnummer":[],"utflyttingFraNorge":[],"vergemaalEllerFremtidsfullmakt":[]},"hentIdenter":{"identer":[{"ident":"68719476736","historisk":false,"gruppe":"FOLKEREGISTERIDENT","metadata":null,"folkeregistermetadata":null},{"ident":"4398046511104","historisk":false,"gruppe":"AKTORID","metadata":null,"folkeregistermetadata":null}]}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING); diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 1215380b..aac938ba 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -5,6 +5,8 @@ */ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMessageConsumer { + public static String PD_TOPIC = KafkaMessageHandlerBinding__mdt.getInstance('PdlPersondokumentHandler').Topic__c; + @TestVisible private static final String PDL_ERROR_STRING = ''; diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 7a6c12da..9bfc5fe8 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -165,7 +165,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { List kafkaMessages = new List(); kafkaMessages.add( new KafkaMessage__c( - CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC, CRM_Key__c = '2594819806563', CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"hentPerson":{"adressebeskyttelse":[],"bostedsadresse":[{"angittFlyttedato":"1972-07-01","gyldigFraOgMed":"1972-07-01T00:00:00","gyldigTilOgMed":null,"coAdressenavn":null,"vegadresse":{"matrikkelId":138391329,"husnummer":"11","husbokstav":null,"bruksenhetsnummer":null,"adressenavn":"Marihandstien","kommunenummer":"1806","tilleggsnavn":null,"postnummer":"8515","bydelsnummer":null,"koordinater":{"x":599891.371546,"y":7592866.900335,"z":null}},"matrikkeladresse":null,"ukjentBosted":null,"utenlandskAdresse":null,"folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:37.045","gyldighetstidspunkt":"1972-07-01T00:00:00","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"e52735a2-be2f-4b2a-b578-dec2f032e8dd","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:37.045","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"doedsfall":[],"foedsel":[{"foedselsaar":1972,"foedselsdato":"1972-07-01","foedeland":"BEL","foedested":"Fødested i/på BELGIA","foedekommune":null,"metadata":{"opplysningsId":"fadd61cf-0da2-4df1-9492-a5fb1532f50f","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:35.412","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false},"folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:35.412","gyldighetstidspunkt":"2022-01-14T15:41:35.412","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null}}],"folkeregisteridentifikator":[{"identifikasjonsnummer":"01077211027","type":"FNR","status":"I_BRUK","folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:34.945","gyldighetstidspunkt":"2022-01-14T15:41:34.945","opphoerstidspunkt":null,"kilde":"srvdolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"4ed45e87-e02b-4aa0-8601-689bbd58f20f","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:35.058","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"srvdolly"}],"historisk":false}}],"folkeregisterpersonstatus":[{"status":"bosatt","forenkletStatus":"bosattEtterFolkeregisterloven","folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:37.899","gyldighetstidspunkt":"2022-01-14T15:41:37.899","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"37065f2d-5f9e-4046-a6d3-9f6856961cd6","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:37.899","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"forelderBarnRelasjon":[],"fullmakt":[],"kjoenn":[{"kjoenn":"KVINNE","folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:36.62","gyldighetstidspunkt":"2022-01-14T15:41:36.62","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"0847b543-0847-4494-9fca-857a1ca51a73","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:36.62","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"navn":[{"fornavn":"ARTIG","mellomnavn":null,"etternavn":"SNERK","forkortetNavn":"SNERK ARTIG","originaltNavn":null,"gyldigFraOgMed":"2022-01-14","folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:36.237","gyldighetstidspunkt":"2022-01-14T15:41:36.237","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"44fbf7a6-6885-48ad-a303-e9d90fa4567f","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:36.237","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"oppholdsadresse":[],"sikkerhetstiltak":[],"sivilstand":[{"type":"UGIFT","gyldigFraOgMed":null,"relatertVedSivilstand":null,"bekreftelsesdato":null,"folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:38.684","gyldighetstidspunkt":"2022-01-14T15:41:38.684","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"2d7f6623-3ba4-44d3-8e04-efced8cd77e3","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:38.684","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"statsborgerskap":[{"land":"NOR","bekreftelsesdato":null,"gyldigFraOgMed":"1972-07-01","gyldigTilOgMed":null,"folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:38.327","gyldighetstidspunkt":"1972-07-01T00:00:00","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"672b293a-b18e-4cd1-9a16-d4a03eb8581d","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:38.326","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"tilrettelagtKommunikasjon":[],"telefonnummer":[],"innflyttingTilNorge":[{"fraflyttingsland":"BEL","fraflyttingsstedIUtlandet":null,"folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:37.532","gyldighetstidspunkt":"1972-07-01T00:00:00","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"5345af76-ac03-4461-9d5c-f17c42ea8a32","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:37.532","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"utflyttingFraNorge":[],"vergemaalEllerFremtidsfullmakt":[]},"hentIdenter":{"identer":[{"ident":"01077211027","historisk":false,"gruppe":"FOLKEREGISTERIDENT","metadata":null,"folkeregistermetadata":null},{"ident":"2594819806563","historisk":false,"gruppe":"AKTORID","metadata":null,"folkeregistermetadata":null}]}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING @@ -187,7 +187,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { List kafkaMessages = new List(); kafkaMessages.add( new KafkaMessage__c( - CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC, CRM_Key__c = '2594819806564', CRM_Value__c = null, CRM_Status__c = KafkaMessageService.STATUS_PENDING @@ -356,7 +356,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { createdDate + '"}', KafkaMessage__c.class ); msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg.CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC; msg.CRM_Key__c = '1000012345678'; msg.CRM_Value__c = 'e30K'; // empty dict: nonnull, so tombstone is false System.Test.startTest(); @@ -385,7 +385,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { createdDate + '"}', KafkaMessage__c.class ); msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg.CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC; msg.CRM_Key__c = '1000012345678'; msg.CRM_Value__c = 'e30K'; // {} System.Test.startTest(); @@ -414,7 +414,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { createdDate + '"}', KafkaMessage__c.class ); msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg.CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC; msg.CRM_Key__c = '1000012345678'; msg.CRM_Value__c = 'e30K'; // {} System.Test.startTest(); @@ -437,7 +437,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { createdDate + '"}', KafkaMessage__c.class ); msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg.CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC; msg.CRM_Key__c = '1000012345678'; msg.CRM_Value__c = 'e30K'; // {} System.Test.startTest(); @@ -469,7 +469,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { createdDate1 + '"}', KafkaMessage__c.class ); msg1.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg1.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg1.CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC; msg1.CRM_Key__c = '1000012345678'; msg1.CRM_Value__c = 'e30K'; // {} // The newest @@ -478,7 +478,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { createdDate2 + '"}', KafkaMessage__c.class ); msg2.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg2.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg2.CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC; msg2.CRM_Key__c = '1000012345678'; msg2.CRM_Value__c = 'e30K'; // {} KafkaMessage__c msg3 = (KafkaMessage__c) JSON.deserializeStrict( @@ -486,7 +486,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { createdDate3 + '"}', KafkaMessage__c.class ); msg3.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg3.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg3.CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC; msg3.CRM_Key__c = '1000012345678'; msg3.CRM_Value__c = 'e30K'; // {} KafkaMessage__c msg4 = (KafkaMessage__c) JSON.deserializeStrict( @@ -494,7 +494,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { createdDate4 + '"}', KafkaMessage__c.class ); msg4.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg4.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg4.CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC; msg4.CRM_Key__c = '1000012345678'; msg4.CRM_Value__c = 'e30K'; // {} System.Test.startTest(); @@ -530,7 +530,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { createdDate1 + '"}', KafkaMessage__c.class ); msg1.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg1.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg1.CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC; msg1.CRM_Key__c = '1000012345678'; msg1.CRM_Value__c = 'e30K'; // {} // The newest @@ -539,7 +539,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { createdDate2 + '"}', KafkaMessage__c.class ); msg2.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg2.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg2.CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC; msg2.CRM_Key__c = '1000012345678'; // CRM_Value__c is null System.Test.startTest(); @@ -564,7 +564,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { createdDate1 + '"}', KafkaMessage__c.class ); msg1.CRM_Status__c = KafkaMessageService.STATUS_PENDING; - msg1.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg1.CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC; msg1.CRM_Key__c = '1000012345678'; // CRM_Value__c is null System.Test.startTest(); @@ -592,7 +592,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { List kafkaMessages = new List(); kafkaMessages.add( new KafkaMessage__c( - CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC, CRM_Key__c = '1000012345678', CRM_Value__c = null ) @@ -644,7 +644,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { CRM_Value__c = (kafkaPerson == null ? null : EncodingUtil.base64Encode(Blob.valueOf(JSON.serialize(kafkaPerson)))), - CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC, CRM_Status__c = KafkaMessageService.STATUS_PENDING ); return kafkaMessage; @@ -1276,7 +1276,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { List kafkaMessages = new List(); kafkaMessages.add( new KafkaMessage__c( - CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC, CRM_Key__c = '9471759694717', CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"hentPerson":{"vergemaalEllerFremtidsfullmakt":[],"utflyttingFraNorge":[],"utenlandskIdentifikasjonsnummer":[],"tilrettelagtKommunikasjon":[],"telefonnummer":[],"statsborgerskap":[],"sivilstand":[],"sikkerhetstiltak":[],"oppholdsadresse":[],"opphold":[],"navn":[{"originaltNavn":null,"metadata":null,"mellomnavn":null,"gyldigFraOgMed":null,"fornavn":null,"forkortetNavn":null,"folkeregistermetadata":null,"etternavn":"TRESTRESEN"}],"kontaktinformasjonForDoedsbo":[],"kontaktadresse":[],"kjoenn":[],"innflyttingTilNorge":[],"identitetsgrunnlag":[],"fullmakt":[],"foreldreansvar":[],"forelderBarnRelasjon":[],"folkeregisterpersonstatus":[{"status":"bosatt","metadata":null,"forenkletStatus":null,"folkeregistermetadata":null}],"folkeregisteridentifikator":[],"foedsel":[],"falskIdentitet":null,"doedsfall":[],"doedfoedtBarn":[],"deltBosted":[],"bostedsadresse":[],"adressebeskyttelse":[{"metadata":null,"gradering":"LOLGRADERT","folkeregistermetadata":null},{"metadata":null,"gradering":"STRENGT_FORTROLIG_UTLAND","folkeregistermetadata":null},{"metadata":null,"gradering":"STRENGT_FORTROLIG","folkeregistermetadata":null},{"metadata":null,"gradering":"FORTROLIG","folkeregistermetadata":null}]},"hentIdenter":{"identer":[{"ident":"9471759694717","historisk":false,"gruppe":"AKTORID"},{"ident":"94717596947","historisk":false,"gruppe":"FOLKEREGISTERIDENT"}]}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING @@ -1407,7 +1407,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { List kafkaMessages = new List(); kafkaMessages.add( new KafkaMessage__c( - CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC, CRM_Key__c = '9011710145110', CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"hentPerson":{"vergemaalEllerFremtidsfullmakt":[],"utflyttingFraNorge":[],"utenlandskIdentifikasjonsnummer":[],"tilrettelagtKommunikasjon":[],"telefonnummer":[],"statsborgerskap":[],"sivilstand":[],"sikkerhetstiltak":[],"oppholdsadresse":[],"opphold":[],"navn":[{"etternavn":"TRESTRESEN"}],"kontaktinformasjonForDoedsbo":[],"kontaktadresse":[],"kjoenn":[],"innflyttingTilNorge":[],"identitetsgrunnlag":[],"fullmakt":[],"foreldreansvar":[],"forelderBarnRelasjon":[],"folkeregisterpersonstatus":[{"status":"bosatt"}],"folkeregisteridentifikator":[],"foedsel":[],"doedsfall":[],"doedfoedtBarn":[],"deltBosted":[],"bostedsadresse":[{"matrikkeladresse":{"postnummer":"4096","kommunenummer":"8192","bydelsnummer":"262144","koordinater":{"x":4806741,"y":1286234,"z":-1}}}],"adressebeskyttelse":[]},"hentIdenter":{"identer":[{"ident":9011710145110,"historisk":false,"gruppe":"AKTORID"},{"ident":90117101451,"historisk":false,"gruppe":"FOLKEREGISTERIDENT"}]}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING @@ -1432,7 +1432,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { List kafkaMessages = new List(); kafkaMessages.add( new KafkaMessage__c( - CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Topic__c = KafkaPdlPersondokumentHandler.PD_TOPIC, CRM_Key__c = '9011710145110', CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"hentPerson":{"vergemaalEllerFremtidsfullmakt":[],"utflyttingFraNorge":[],"utenlandskIdentifikasjonsnummer":[],"tilrettelagtKommunikasjon":[],"telefonnummer":[],"statsborgerskap":[],"sivilstand":[],"sikkerhetstiltak":[],"oppholdsadresse":[],"opphold":[],"navn":[{"etternavn":"TRESTRESEN"}],"kontaktinformasjonForDoedsbo":[],"kontaktadresse":[],"kjoenn":[],"innflyttingTilNorge":[],"identitetsgrunnlag":[],"fullmakt":[],"foreldreansvar":[],"forelderBarnRelasjon":[],"folkeregisterpersonstatus":[{"status":"bosatt"}],"folkeregisteridentifikator":[],"foedsel":[],"doedsfall":[],"doedfoedtBarn":[],"deltBosted":[],"bostedsadresse":[{"matrikkeladresse":{"postnummer":"4096","kommunenummer":"8192","bydelsnummer":"262144","koordinater":{"x":4806741,"y":1286234,"z":-1}}}],"adressebeskyttelse":[{"gradering":"STRENGT_FORTROLIG"}]},"hentIdenter":{"identer":[{"ident":9011710145110,"historisk":false,"gruppe":"AKTORID"},{"ident":90117101451,"historisk":false,"gruppe":"FOLKEREGISTERIDENT"}]}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING From 5e58b9c7afad38388d639fc22c81f854fe1cb8c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 22 May 2024 10:35:20 +0200 Subject: [PATCH 129/159] add test for multiple interpreter languages --- .../classes/KafkaPdlPersondokumentHandler.cls | 1 - .../KafkaPdlPersondokumentHandlerTest.cls | 24 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index aac938ba..06557163 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -451,7 +451,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * a list of the languages for which an interpreter is required. * @param comms Collection of facilitated communication * @return null or strings joined with ';' - * TODO: write test for multiple of these */ @TestVisible private static String interpreterLanguagesString(PdlObject[] comms) { diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 9bfc5fe8..8f5666a8 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1506,4 +1506,28 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('HYDE', persons[0].INT_LastName__c); Assert.isNull(persons[0].INT_FirstName__c); } + + /** + * Tests that interpreter languages arrive in the correct format when there + * are more or less than one of them. + */ + @IsTest + static void testNoneOrMultipleInterpreterLanguages() { + PdlTilrettelagtkommunikasjon[] polyComms = new List(); + PdlTilrettelagtkommunikasjon[] noComms = new List(); + PdlTilrettelagtkommunikasjon comm1 = new PdlTilrettelagtkommunikasjon(); + comm1.talespraaktolk = new PDL_Tolk(); + comm1.talespraaktolk.spraak = '漢語'; + polyComms.add(comm1); + PdlTilrettelagtkommunikasjon comm2 = new PdlTilrettelagtkommunikasjon(); + comm2.talespraaktolk = new PDL_Tolk(); + comm2.talespraaktolk.spraak = 'IT'; + polyComms.add(comm2); + Test.startTest(); + String polyResult = KafkaPdlPersondokumentHandler.interpreterLanguagesString(polyComms); + String noResult = KafkaPdlPersondokumentHandler.interpreterLanguagesString(noComms); + Test.stopTest(); + Assert.areEqual('漢語;IT', polyResult); + Assert.isNull(noResult); + } } From 6cac04b61ff98869912235d1ef29bcff75eec2c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 22 May 2024 10:42:18 +0200 Subject: [PATCH 130/159] (minor) clean up todos --- force-app/pdl-handler/classes/KafkaPdlGtHandler.cls | 1 - .../pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 3 ++- .../pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index c378a78e..4e6ea270 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -80,7 +80,6 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer logger.info('Not setting GT from UDEFINERT, clearing all GT fields', null); } else if (gt.gtType == 'UTLAND') { logger.info('GT from abroad, doing nothing.', null); - // TODO? } else { logger.error('Not setting GT, unknown gtType.', null); } diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 06557163..39fadef6 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -307,6 +307,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess person.INT_AddressDistrictNumber__c = bo.matrikkeladresse.bydelsnummer; person.INT_Coordinates__c = formatCoordinates(bo.matrikkeladresse.koordinater); } + // ...PDL skal til enhver tid kun ha en gyldig bostedsadresse per // person. Hver gang en ny bostedsadresse blir registrert så vil den // forrige bli historisk. Norsk bostedsadresse vil alltid ha Freg som @@ -322,7 +323,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess // Personer med en gyldig bostedsadresse i Norge, kan ikke bli // registrert med en utenlandsk bostedsadresse. Da må den norske // adressen først opphøres i Folkeregisteret. - // ...TODO: pull in the foreign address, probably + // (to do at some point, probably: pull in the foreign address) // oppholdsadresser // assumption: vegadresse has first pri, then utenlandskAdresse, then ukjentbosted diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 8f5666a8..9827d423 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -839,7 +839,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { @isTest /** - * TODO check what exactly this tests + * TODO: check what exactly this tests */ static void insertKafkaMessageUpdateError() { insert new Person__c( From 1642eb48c5b139ce51b9ac52e47de52f7e2647c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 28 May 2024 11:56:47 +0200 Subject: [PATCH 131/159] regardless, don't put the '-tagged' in the handler --- ...kaMessageHandlerBinding.PdlPersondokumentHandler.md-meta.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlPersondokumentHandler.md-meta.xml b/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlPersondokumentHandler.md-meta.xml index 361bc6b3..31fc7822 100644 --- a/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlPersondokumentHandler.md-meta.xml +++ b/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlPersondokumentHandler.md-meta.xml @@ -16,7 +16,7 @@ Topic__c - pdl.pdl-persondokument-tagged-v1 + pdl.pdl-persondokument-v1 ApexJobType__c From 240d9b15338353c15fc886e89ff8edfc144e5102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 27 May 2024 14:09:49 +0200 Subject: [PATCH 132/159] minor refactor KafkaMessageService --- .../default/classes/KafkaMessageService.cls | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/force-app/main/default/classes/KafkaMessageService.cls b/force-app/main/default/classes/KafkaMessageService.cls index 94cf1c06..2eb659db 100644 --- a/force-app/main/default/classes/KafkaMessageService.cls +++ b/force-app/main/default/classes/KafkaMessageService.cls @@ -12,7 +12,10 @@ public with sharing class KafkaMessageService { this.messages = messages; } - public void handleMessages() { + /** + * Maps each topic to its appropriate consumer. + */ + private void setupHandlerBindings() { for (KafkaMessageHandlerBinding__mdt binding : [ SELECT Id, Topic__c, ApexClass__c FROM KafkaMessageHandlerBinding__mdt @@ -22,13 +25,19 @@ public with sharing class KafkaMessageService { (IKafkaMessageConsumer) Type.forName(binding.ApexClass__c).newInstance() ); } + } + /** + * Sorts messages into their respective topics. Resets the status and error + * fields, which honestly should probably already be pending and '', + * respectively. + */ + private Map> getMessagesByTopic() { Map> messagesByTopic = new Map>(); for (KafkaMessage__c msg : messages) { // Reset processing status fields msg.CRM_Status__c = KafkaMessageService.STATUS_PENDING; msg.CRM_ErrorMessage__c = ''; - // Build map of messages by topic if (messagesByTopic.containsKey(msg.CRM_Topic__c)) { messagesByTopic.get(msg.CRM_Topic__c).add(msg); @@ -36,7 +45,12 @@ public with sharing class KafkaMessageService { messagesByTopic.put(msg.CRM_Topic__c, new List{ msg }); } } + return messagesByTopic; + } + public void handleMessages() { + setupHandlerBindings(); + Map> messagesByTopic = getMessagesByTopic(); List messagesToUpdate = new List(); for (String topic : messagesByTopic.keySet()) { From fa6344b68aec860fe99a2d7c2562baf833ac543c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 27 May 2024 14:19:15 +0200 Subject: [PATCH 133/159] minor refactor KafkaMessageHandler --- .../default/classes/KafkaMessageHandler.cls | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/force-app/main/default/classes/KafkaMessageHandler.cls b/force-app/main/default/classes/KafkaMessageHandler.cls index df71a777..4df5f347 100644 --- a/force-app/main/default/classes/KafkaMessageHandler.cls +++ b/force-app/main/default/classes/KafkaMessageHandler.cls @@ -88,6 +88,18 @@ public inherited sharing class KafkaMessageHandler extends MyTriggers { } } + private static Map getHandlerBindingByTopic(Set topicSet) { + Map handlerBindingByTopic = new Map(); + for (KafkaMessageHandlerBinding__mdt binding : [ + SELECT Id, Topic__c, Priority__c, ApexJobType__c + FROM KafkaMessageHandlerBinding__mdt + WHERE Topic__c = :topicSet + ]) { + handlerBindingByTopic.put(binding.Topic__c, binding); + } + return handlerBindingByTopic; + } + /** * Instantiates AsyncRequest__c records, including setting values for the CRM_Priority__c field based on * priority associated with the related Kafka Message Handler Binding record for a given messages CRM_Topic__c value @@ -99,14 +111,7 @@ public inherited sharing class KafkaMessageHandler extends MyTriggers { if (!KafkaIntegrationCustomSetting.processingEnabled || recordIdsToProcessByTopic.size() == 0) return asyncRequests; - Map handlerBindingByTopic = new Map(); - for (KafkaMessageHandlerBinding__mdt binding : [ - SELECT Id, Topic__c, Priority__c, ApexJobType__c - FROM KafkaMessageHandlerBinding__mdt - WHERE Topic__c = :recordIdsToProcessByTopic.keySet() - ]) { - handlerBindingByTopic.put(binding.Topic__c, binding); - } + Map handlerBindingByTopic = getHandlerBindingByTopic(recordIdsToProcessByTopic.keySet()); for (String topic : recordIdsToProcessByTopic.keySet()) { if (!handlerBindingByTopic.containsKey(topic)) { From 41e96d53fedcec47c42a6341a2c5665510c2257d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 28 May 2024 15:30:54 +0200 Subject: [PATCH 134/159] use separate metadata for sandboxes. breaks tests. --- .../default/classes/KafkaMessageService.cls | 20 ++++++++++++++----- .../SandboxOverrideTopic__c.field-meta.xml | 13 ++++++++++++ ...nding.PdlPersondokumentHandler.md-meta.xml | 4 ++++ 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 force-app/main/default/objects/KafkaMessageHandlerBinding__mdt/fields/SandboxOverrideTopic__c.field-meta.xml diff --git a/force-app/main/default/classes/KafkaMessageService.cls b/force-app/main/default/classes/KafkaMessageService.cls index 2eb659db..39343c44 100644 --- a/force-app/main/default/classes/KafkaMessageService.cls +++ b/force-app/main/default/classes/KafkaMessageService.cls @@ -14,16 +14,26 @@ public with sharing class KafkaMessageService { /** * Maps each topic to its appropriate consumer. + * In prod, map every Topic__c, otherwise, let SandboxOverrideTopic__c take + * precedence. */ private void setupHandlerBindings() { for (KafkaMessageHandlerBinding__mdt binding : [ - SELECT Id, Topic__c, ApexClass__c + SELECT Id, Topic__c, SandboxOverrideTopic__c, ApexClass__c FROM KafkaMessageHandlerBinding__mdt ]) { - handlerBindings.put( - binding.Topic__c, - (IKafkaMessageConsumer) Type.forName(binding.ApexClass__c).newInstance() - ); + if([SELECT IsSandbox FROM Organization][0].IsSandbox && + String.isNotBlank(binding.SandboxOverrideTopic__c)) { + handlerBindings.put( + binding.SandboxOverrideTopic__c, + (IKafkaMessageConsumer) Type.forName(binding.ApexClass__c).newInstance() + ); + } else { + handlerBindings.put( + binding.Topic__c, + (IKafkaMessageConsumer) Type.forName(binding.ApexClass__c).newInstance() + ); + } } } diff --git a/force-app/main/default/objects/KafkaMessageHandlerBinding__mdt/fields/SandboxOverrideTopic__c.field-meta.xml b/force-app/main/default/objects/KafkaMessageHandlerBinding__mdt/fields/SandboxOverrideTopic__c.field-meta.xml new file mode 100644 index 00000000..c0de61d6 --- /dev/null +++ b/force-app/main/default/objects/KafkaMessageHandlerBinding__mdt/fields/SandboxOverrideTopic__c.field-meta.xml @@ -0,0 +1,13 @@ + + + SandboxOverrideTopic__c + Overrides Topic__c when in a sandbox + false + DeveloperControlled + When it is not desirable that all events on the topic given in Topic__c is consumed in a sandbox, this field specifies an alternative topic. + + 255 + false + Text + false + diff --git a/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlPersondokumentHandler.md-meta.xml b/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlPersondokumentHandler.md-meta.xml index 31fc7822..001ec288 100644 --- a/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlPersondokumentHandler.md-meta.xml +++ b/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlPersondokumentHandler.md-meta.xml @@ -18,6 +18,10 @@ Topic__c pdl.pdl-persondokument-v1 + + SandboxOverrideTopic__c + pdl.pdl-persondokument-tagged-v1 + ApexJobType__c Batch Apex From 799dd9962431881f4a031cfa2a2a1d53048b75a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Tue, 28 May 2024 17:38:05 +0200 Subject: [PATCH 135/159] fix PD_TOPIC in tests --- .../pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 39fadef6..c8e4b0c8 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -5,7 +5,10 @@ */ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMessageConsumer { - public static String PD_TOPIC = KafkaMessageHandlerBinding__mdt.getInstance('PdlPersondokumentHandler').Topic__c; + public static String PD_TOPIC = ( + [SELECT IsSandbox FROM Organization][0].IsSandbox ? + KafkaMessageHandlerBinding__mdt.getInstance('PdlPersondokumentHandler').SandboxOverrideTopic__c : + KafkaMessageHandlerBinding__mdt.getInstance('PdlPersondokumentHandler').Topic__c); @TestVisible private static final String PDL_ERROR_STRING = ''; From d2f6d227302d3810fd834ba0c42039e2e3e41d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 29 May 2024 12:19:04 +0200 Subject: [PATCH 136/159] slightly increase pdl kafka handler priority --- ...kaMessageHandlerBinding.PdlPersondokumentHandler.md-meta.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlPersondokumentHandler.md-meta.xml b/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlPersondokumentHandler.md-meta.xml index 001ec288..d4f81c91 100644 --- a/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlPersondokumentHandler.md-meta.xml +++ b/force-app/pdl-handler/customMetadata/KafkaMessageHandlerBinding.PdlPersondokumentHandler.md-meta.xml @@ -12,7 +12,7 @@ Priority__c - 20.0 + 19.0 Topic__c From ca91efc4dbd89883762d6d19192915082ccd3df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 29 May 2024 10:17:42 +0200 Subject: [PATCH 137/159] write failing test for priority --- .../classes/KafkaMessageHandlerTest.cls | 31 +++++++++++++++++++ .../KafkaMessageHandlerTest.cls-meta.xml | 5 +++ 2 files changed, 36 insertions(+) create mode 100644 force-app/main/default/classes/KafkaMessageHandlerTest.cls create mode 100644 force-app/main/default/classes/KafkaMessageHandlerTest.cls-meta.xml diff --git a/force-app/main/default/classes/KafkaMessageHandlerTest.cls b/force-app/main/default/classes/KafkaMessageHandlerTest.cls new file mode 100644 index 00000000..c436ff2c --- /dev/null +++ b/force-app/main/default/classes/KafkaMessageHandlerTest.cls @@ -0,0 +1,31 @@ +/** + * Tests methods specific to KafkaMessageHandler. See KafkaMessageServiceTest + * for similar tests. + */ +@IsTest +public with sharing class KafkaMessageHandlerTest { + + /** + * Tests that the topic given in SandboxOverrideTopic__c is picked up by the + * handler. + */ + @IsTest + private static void handleSandboxOverrideTopicPriority() { + // Disable Sandbox-specific filter in order to test production functionality + KafkaEnhetFilter.bypassFilter = true; + KafkaMessage__c msg = new KafkaMessage__c(); + msg.CRM_Key__c = '1792160394037'; + msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; + msg.CRM_Value__c = null; + insert msg; + Test.startTest(); + new KafkaMessageService(new List{ msg }).handleMessages(); + Test.stopTest(); + System.assertEquals( + KafkaMessageService.STATUS_PROCESSED, + [SELECT Id, CRM_Status__c FROM KafkaMessage__c WHERE Id = :msg.Id LIMIT 1] + .CRM_Status__c + ); + System.assertEquals(19, [SELECT CRM_Priority__c FROM AsyncRequest__c LIMIT 1].CRM_Priority__c); + } +} diff --git a/force-app/main/default/classes/KafkaMessageHandlerTest.cls-meta.xml b/force-app/main/default/classes/KafkaMessageHandlerTest.cls-meta.xml new file mode 100644 index 00000000..b1a915c9 --- /dev/null +++ b/force-app/main/default/classes/KafkaMessageHandlerTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + From 9548f23bc4c683b3fa1118cabd972257e2f87918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 29 May 2024 09:17:49 +0200 Subject: [PATCH 138/159] read correct job type and priority --- .../default/classes/KafkaMessageHandler.cls | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/force-app/main/default/classes/KafkaMessageHandler.cls b/force-app/main/default/classes/KafkaMessageHandler.cls index 4df5f347..be6e648d 100644 --- a/force-app/main/default/classes/KafkaMessageHandler.cls +++ b/force-app/main/default/classes/KafkaMessageHandler.cls @@ -88,6 +88,14 @@ public inherited sharing class KafkaMessageHandler extends MyTriggers { } } + /** + * Fetches a map of handler bindings based on their topic, to be used to set + * ApexJobType__c and Priority__c. + * @param topicSet topics gathered from inserted kafka messages, which may + * correspond to either Topic__c or SandboxOverrideTopic__c in + * KafkaMessageHandlerBinding__mdt. + * @return Mapping from topic to binding. + */ private static Map getHandlerBindingByTopic(Set topicSet) { Map handlerBindingByTopic = new Map(); for (KafkaMessageHandlerBinding__mdt binding : [ @@ -97,6 +105,15 @@ public inherited sharing class KafkaMessageHandler extends MyTriggers { ]) { handlerBindingByTopic.put(binding.Topic__c, binding); } + if([SELECT IsSandbox FROM Organization][0].IsSandbox) { + for (KafkaMessageHandlerBinding__mdt binding : [ + SELECT Id, SandboxOverrideTopic__c, Priority__c, ApexJobType__c + FROM KafkaMessageHandlerBinding__mdt + WHERE SandboxOverrideTopic__c = :topicSet + ]) { + handlerBindingByTopic.put(binding.SandboxOverrideTopic__c, binding); + } + } return handlerBindingByTopic; } From dcd295c32aa57c2dfed5226cb6e931e835d982d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 29 May 2024 20:27:29 +0200 Subject: [PATCH 139/159] minor cleanup --- .../pdl-handler/classes/KafkaPdlGtHandler.cls | 1 - .../classes/KafkaPdlGtHandlerTest.cls | 6 ++-- .../classes/KafkaPdlPdAndGtHandlersTest.cls | 4 ++- .../classes/KafkaPdlPersondokumentHandler.cls | 32 ++----------------- 4 files changed, 9 insertions(+), 34 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index 4e6ea270..67591f9c 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -98,7 +98,6 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer KafkaPersonGT kafkaPerson = KafkaPersonGT.parse(decodedValue); Person__c person = personFromKafkaPerson(kafkaPerson); person.INT_LastUpdatedFromPDL__c = message.createdDate; - // ... return person; } diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index 39a10956..585523b7 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -11,14 +11,16 @@ private with sharing class KafkaPdlGtHandlerTest { */ private static void handleMessages() { new KafkaMessageService( - [SELECT Id, CreatedDate, CRM_Topic__c, CRM_Key__c, CRM_Value__c FROM KafkaMessage__c WHERE CRM_Status__c = :KafkaMessageService.STATUS_PENDING] + [SELECT Id, CreatedDate, CRM_Topic__c, CRM_Key__c, CRM_Value__c + FROM KafkaMessage__c + WHERE CRM_Status__c = :KafkaMessageService.STATUS_PENDING] ).handleMessages(); } /** * Create a message for inserting a person document. * See KafkaPdlPersondokumentHandlerTest for more information. - * Explicitly set status; which would otherwise only get called when using + * Explicitly set status, which would otherwise only get called when using * KafkaMessageService (i.e. upon insert). */ private static KafkaMessage__c createPersonDocumentMessage( diff --git a/force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls b/force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls index bd103397..03e9245a 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls @@ -10,7 +10,9 @@ private with sharing class KafkaPdlPdAndGtHandlersTest { */ private static void handleMessages() { new KafkaMessageService( - [SELECT Id, CreatedDate, CRM_Topic__c, CRM_Key__c, CRM_Value__c FROM KafkaMessage__c WHERE CRM_Status__c = :KafkaMessageService.STATUS_PENDING] + [SELECT Id, CreatedDate, CRM_Topic__c, CRM_Key__c, CRM_Value__c + FROM KafkaMessage__c + WHERE CRM_Status__c = :KafkaMessageService.STATUS_PENDING] ).handleMessages(); } diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index c8e4b0c8..f5f68271 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -10,9 +10,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess KafkaMessageHandlerBinding__mdt.getInstance('PdlPersondokumentHandler').SandboxOverrideTopic__c : KafkaMessageHandlerBinding__mdt.getInstance('PdlPersondokumentHandler').Topic__c); - @TestVisible - private static final String PDL_ERROR_STRING = ''; - /** * Get some transformation into an integer, so information can be hidden * based on whether or not this integer is greater than some constant. @@ -404,30 +401,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } } - @TestVisible - private void setMunicipalityAndGT(Person__c person, KafkaPerson2 kafkaPerson) { - // Set GT Municipality and District numbers - if (kafkaPerson.kommunenummerFraGt != PDL_ERROR_STRING) { - person.INT_GTMunicipalityNumber__c = kafkaPerson.kommunenummerFraGt; - person.INT_RegionNumber__c = kafkaPerson.kommunenummerFraGt.left(2); - } - if (kafkaPerson.bydelsnummerFraGt != PDL_ERROR_STRING) { - person.INT_RegionNumber__c = kafkaPerson.bydelsnummerFraGt.left(2); - person.INT_GTDistrictNumber__c = kafkaPerson.bydelsnummerFraGt; - } - // Set Municipality and District from GT if available, otherwise from Bostedsaddresse - if (person.INT_GTMunicipalityNumber__c != null) { - person.INT_MunicipalityNumber__c = person.INT_GTMunicipalityNumber__c; - } else if (person.INT_AddressMunicipalityNumber__c != null) { - person.INT_MunicipalityNumber__c = person.INT_AddressMunicipalityNumber__c; - } - if (person.INT_GTDistrictNumber__c != null) { - person.INT_DistrictNumber__c = person.INT_GTDistrictNumber__c; - } else if (person.INT_AddressDistrictNumber__c != null) { - person.INT_DistrictNumber__c = person.INT_AddressDistrictNumber__c; - } - } - /** * Return the date of death * @param deaths list deaths. _historisk_ is not relevant here. [0] @@ -527,7 +500,6 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess private void validateListSizes(KafkaPerson3 kafkaPerson) { PdlHentperson hp = kafkaPerson.hentPerson; KafkaPerson3.HentIdenter hentIdenter = kafkaPerson.hentIdenter; - List objectsFailingValidation = new List(); if(hentIdenter.identer == null) { if (hp.folkeregisteridentifikator.size() == 0) { throw new PdlMissingEntryException('No folkeregisteridentifikator found'); } @@ -565,7 +537,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } /** - * Takes ISO code value and gives country value in return + * Takes ISO code value and gives country ID in return * @param isoCode ISO-code. either ISO 2 or ISO 3 standard * @return country in English */ @@ -696,7 +668,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess /** * Sets empty value for all Person__c fields set by this handler. Ensures * that e.g. INT_DateOfDeath__c is removed when it has previously been - * erroneously set — and then corrected by creating a person document that + * erroneously set and then corrected by creating a person document that * does not contain a date of death. * @param person record to modify * TODO: ensure we haven't missed anything. From d683957624218494fca4daab917bf8e23944a3ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 31 May 2024 12:13:33 +0200 Subject: [PATCH 140/159] run sandbox test only in sandboxes --- .../classes/KafkaMessageHandlerTest.cls | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/force-app/main/default/classes/KafkaMessageHandlerTest.cls b/force-app/main/default/classes/KafkaMessageHandlerTest.cls index c436ff2c..5f5a7335 100644 --- a/force-app/main/default/classes/KafkaMessageHandlerTest.cls +++ b/force-app/main/default/classes/KafkaMessageHandlerTest.cls @@ -11,21 +11,22 @@ public with sharing class KafkaMessageHandlerTest { */ @IsTest private static void handleSandboxOverrideTopicPriority() { - // Disable Sandbox-specific filter in order to test production functionality - KafkaEnhetFilter.bypassFilter = true; - KafkaMessage__c msg = new KafkaMessage__c(); - msg.CRM_Key__c = '1792160394037'; - msg.CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1'; - msg.CRM_Value__c = null; - insert msg; - Test.startTest(); - new KafkaMessageService(new List{ msg }).handleMessages(); - Test.stopTest(); - System.assertEquals( - KafkaMessageService.STATUS_PROCESSED, - [SELECT Id, CRM_Status__c FROM KafkaMessage__c WHERE Id = :msg.Id LIMIT 1] - .CRM_Status__c - ); - System.assertEquals(19, [SELECT CRM_Priority__c FROM AsyncRequest__c LIMIT 1].CRM_Priority__c); + // These topics will only be picked up in sandboxes, so only run there. + if([SELECT IsSandbox FROM Organization][0].IsSandbox) { + KafkaMessage__c msg = new KafkaMessage__c( + CRM_Key__c = '1792160394037', + CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Value__c = null); + insert msg; + Test.startTest(); + new KafkaMessageService(new List{ msg }).handleMessages(); + Test.stopTest(); + System.assertEquals( + KafkaMessageService.STATUS_PROCESSED, + [SELECT Id, CRM_Status__c FROM KafkaMessage__c WHERE Id = :msg.Id LIMIT 1] + .CRM_Status__c + ); + System.assertEquals(19, [SELECT CRM_Priority__c FROM AsyncRequest__c LIMIT 1].CRM_Priority__c); + } } } From 569d6c3c4fa0a6b20aeadf89a1195948ea0263f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 31 May 2024 15:00:42 +0200 Subject: [PATCH 141/159] add field also to layout and list view --- ...ka Message Handler Binding Layout.layout-meta.xml | 12 ++++++++---- .../listViews/All_Bindings.listView-meta.xml | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/force-app/main/default/layouts/KafkaMessageHandlerBinding__mdt-Kafka Message Handler Binding Layout.layout-meta.xml b/force-app/main/default/layouts/KafkaMessageHandlerBinding__mdt-Kafka Message Handler Binding Layout.layout-meta.xml index 494e281d..321b732d 100644 --- a/force-app/main/default/layouts/KafkaMessageHandlerBinding__mdt-Kafka Message Handler Binding Layout.layout-meta.xml +++ b/force-app/main/default/layouts/KafkaMessageHandlerBinding__mdt-Kafka Message Handler Binding Layout.layout-meta.xml @@ -1,4 +1,4 @@ - + false @@ -26,6 +26,10 @@ Required Topic__c + + Edit + SandboxOverrideTopic__c + Edit Priority__c @@ -70,9 +74,9 @@ false false false - - - + + + false diff --git a/force-app/main/default/objects/KafkaMessageHandlerBinding__mdt/listViews/All_Bindings.listView-meta.xml b/force-app/main/default/objects/KafkaMessageHandlerBinding__mdt/listViews/All_Bindings.listView-meta.xml index 6ebe42b3..b59e6c57 100644 --- a/force-app/main/default/objects/KafkaMessageHandlerBinding__mdt/listViews/All_Bindings.listView-meta.xml +++ b/force-app/main/default/objects/KafkaMessageHandlerBinding__mdt/listViews/All_Bindings.listView-meta.xml @@ -4,6 +4,7 @@ MasterLabel DeveloperName Topic__c + SandboxOverrideTopic__c Priority__c ApexClass__c Description__c From 46c2cec78d113802a24c8ab75dd1884469bdd95b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 3 Jun 2024 14:28:43 +0200 Subject: [PATCH 142/159] typo --- force-app/main/default/classes/KafkaMessageHandler.cls | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/force-app/main/default/classes/KafkaMessageHandler.cls b/force-app/main/default/classes/KafkaMessageHandler.cls index be6e648d..1c1157c9 100644 --- a/force-app/main/default/classes/KafkaMessageHandler.cls +++ b/force-app/main/default/classes/KafkaMessageHandler.cls @@ -96,7 +96,7 @@ public inherited sharing class KafkaMessageHandler extends MyTriggers { * KafkaMessageHandlerBinding__mdt. * @return Mapping from topic to binding. */ - private static Map getHandlerBindingByTopic(Set topicSet) { + private static Map getHandlerBindingsByTopic(Set topicSet) { Map handlerBindingByTopic = new Map(); for (KafkaMessageHandlerBinding__mdt binding : [ SELECT Id, Topic__c, Priority__c, ApexJobType__c @@ -128,7 +128,7 @@ public inherited sharing class KafkaMessageHandler extends MyTriggers { if (!KafkaIntegrationCustomSetting.processingEnabled || recordIdsToProcessByTopic.size() == 0) return asyncRequests; - Map handlerBindingByTopic = getHandlerBindingByTopic(recordIdsToProcessByTopic.keySet()); + Map handlerBindingByTopic = getHandlerBindingsByTopic(recordIdsToProcessByTopic.keySet()); for (String topic : recordIdsToProcessByTopic.keySet()) { if (!handlerBindingByTopic.containsKey(topic)) { From 7c6a000ea6e43520bae59f7def0a016c6067b48d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 3 Jun 2024 14:28:46 +0200 Subject: [PATCH 143/159] drop unnecessary soql queries --- force-app/main/default/classes/KafkaMessageService.cls | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/force-app/main/default/classes/KafkaMessageService.cls b/force-app/main/default/classes/KafkaMessageService.cls index 39343c44..9b68f31e 100644 --- a/force-app/main/default/classes/KafkaMessageService.cls +++ b/force-app/main/default/classes/KafkaMessageService.cls @@ -6,6 +6,7 @@ public with sharing class KafkaMessageService { private Map handlerBindings = new Map(); private List messages; + private static Boolean isSandbox = [SELECT IsSandbox FROM Organization][0].IsSandbox; // Before Insert constructor - takes a list of Kafka Messages that don't yet have a record id public KafkaMessageService(List messages) { @@ -22,7 +23,7 @@ public with sharing class KafkaMessageService { SELECT Id, Topic__c, SandboxOverrideTopic__c, ApexClass__c FROM KafkaMessageHandlerBinding__mdt ]) { - if([SELECT IsSandbox FROM Organization][0].IsSandbox && + if(isSandbox && String.isNotBlank(binding.SandboxOverrideTopic__c)) { handlerBindings.put( binding.SandboxOverrideTopic__c, From dc02d24851d03cd8ca042d2676b8e2a6382ce840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Wed, 5 Jun 2024 11:54:34 +0200 Subject: [PATCH 144/159] fix exception when coordinates are null --- .../pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 3 +++ 1 file changed, 3 insertions(+) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index f5f68271..9cd66f1a 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -272,6 +272,9 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * in the future. */ private String formatCoordinates(PDL_Koordinater k) { + if(k == null) { + return null; + } return String.format('x={0}, y={1}, z={2}', new List{ k.x, k.y, From 22268ac963cfb927c9f9c702801b25951962da6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Mon, 17 Jun 2024 14:58:14 +0200 Subject: [PATCH 145/159] update README --- README.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2689594e..3185c641 100755 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ This package contains the `KafkaMessage__c` sObject and related Apex logic in order to receive JSON payloads representing changes from the Kafka CDC pipeline. -A trigger on the `KafkaMessage__c` sObject will create enqueue asynchronous -processing request through the asynchronous processing framework that is part of -the crm-platform-base package. +A trigger on the `KafkaMessage__c` sObject will enqueue asynchronous processing +requests through the asynchronous processing framework that is part of the +**crm-platform-base** package. ## Custom Metadata Bindings @@ -47,11 +47,15 @@ message payload related to a specific Kafka topic. `KafkaMessageHandlerBinding__mdt` record is found corresponding to the `Topic__c` value, the relevant `KafkaMessage__c` record is updated with an error. The message can then be retried after the error has been addressed. + i. If `KafkaMessageHandlerBinding__mdt.SandboxOverrideTopic__c` exists, it is + its value which will correspond with `KafkaMessage__c.Topic__c` in scratch + orgs and sandboxes. `KafkaMessageHandlerBinding__mdt.Topic__c` will in this + case remain unused. 5. The Apex class registered by the `KafkaMessageHandlerBinding__mdt` binding - executes the business logic corresponding to the `Topic__c` value. - If an - exception occurs, the relevant`KafkaMessage__c` record is updated with an + executes the business logic corresponding to the `Topic__c` value. If an + exception occurs, the relevant `KafkaMessage__c` record is updated with an error. The message can then be retried after the error has been addressed. - + ## Synchronous kafka message handling To process incoming kafka messages in a synchronous context the following @@ -60,7 +64,7 @@ pattern should be followed: defined [here](https://github.com/navikt/crm-platform-oppgave/tree/master/force-app/main/default/objects/Kafka_Oppgave_Event__e). 2. Create a trigger and separate trigger handler to process the incoming events. -3. The processing itself should be implemented using the IKafkaMessageConsumer +3. The processing itself should be implemented using the `IKafkaMessageConsumer` interface such that error handling can be performed easily storing failed events as `KafkaMessage__c` records. An example of this can be viewed [here](https://github.com/navikt/crm-platform-oppgave/blob/master/force-app/main/default/classes/kafka/CRM_KafkaOppgaveEventHandler.cls) From 92b459b68a901a793ee58f5f9e0210fbc211d180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Thu, 4 Jul 2024 13:29:15 +0200 Subject: [PATCH 146/159] apply some of the advice from npx prettier --- .../default/classes/KafkaMessageHandler.cls | 6 ++-- .../classes/KafkaMessageHandlerTest.cls | 13 ++++---- .../default/classes/KafkaMessageService.cls | 3 +- .../classes/KafkaPdlGtHandlerTest.cls | 12 +++---- .../classes/KafkaPdlPdAndGtHandlersTest.cls | 4 +-- .../KafkaPdlPersondokumentHandlerTest.cls | 32 +++++++++---------- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/force-app/main/default/classes/KafkaMessageHandler.cls b/force-app/main/default/classes/KafkaMessageHandler.cls index 1c1157c9..de53e5d6 100644 --- a/force-app/main/default/classes/KafkaMessageHandler.cls +++ b/force-app/main/default/classes/KafkaMessageHandler.cls @@ -105,7 +105,7 @@ public inherited sharing class KafkaMessageHandler extends MyTriggers { ]) { handlerBindingByTopic.put(binding.Topic__c, binding); } - if([SELECT IsSandbox FROM Organization][0].IsSandbox) { + if ([SELECT IsSandbox FROM Organization][0].IsSandbox) { for (KafkaMessageHandlerBinding__mdt binding : [ SELECT Id, SandboxOverrideTopic__c, Priority__c, ApexJobType__c FROM KafkaMessageHandlerBinding__mdt @@ -128,7 +128,9 @@ public inherited sharing class KafkaMessageHandler extends MyTriggers { if (!KafkaIntegrationCustomSetting.processingEnabled || recordIdsToProcessByTopic.size() == 0) return asyncRequests; - Map handlerBindingByTopic = getHandlerBindingsByTopic(recordIdsToProcessByTopic.keySet()); + Map handlerBindingByTopic = getHandlerBindingsByTopic( + recordIdsToProcessByTopic.keySet() + ); for (String topic : recordIdsToProcessByTopic.keySet()) { if (!handlerBindingByTopic.containsKey(topic)) { diff --git a/force-app/main/default/classes/KafkaMessageHandlerTest.cls b/force-app/main/default/classes/KafkaMessageHandlerTest.cls index 5f5a7335..598c15d5 100644 --- a/force-app/main/default/classes/KafkaMessageHandlerTest.cls +++ b/force-app/main/default/classes/KafkaMessageHandlerTest.cls @@ -4,7 +4,6 @@ */ @IsTest public with sharing class KafkaMessageHandlerTest { - /** * Tests that the topic given in SandboxOverrideTopic__c is picked up by the * handler. @@ -12,19 +11,19 @@ public with sharing class KafkaMessageHandlerTest { @IsTest private static void handleSandboxOverrideTopicPriority() { // These topics will only be picked up in sandboxes, so only run there. - if([SELECT IsSandbox FROM Organization][0].IsSandbox) { + if ([SELECT IsSandbox FROM Organization][0].IsSandbox) { KafkaMessage__c msg = new KafkaMessage__c( - CRM_Key__c = '1792160394037', - CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', - CRM_Value__c = null); + CRM_Key__c = '1792160394037', + CRM_Topic__c = 'pdl.pdl-persondokument-tagged-v1', + CRM_Value__c = null + ); insert msg; Test.startTest(); new KafkaMessageService(new List{ msg }).handleMessages(); Test.stopTest(); System.assertEquals( KafkaMessageService.STATUS_PROCESSED, - [SELECT Id, CRM_Status__c FROM KafkaMessage__c WHERE Id = :msg.Id LIMIT 1] - .CRM_Status__c + [SELECT Id, CRM_Status__c FROM KafkaMessage__c WHERE Id = :msg.Id LIMIT 1].CRM_Status__c ); System.assertEquals(19, [SELECT CRM_Priority__c FROM AsyncRequest__c LIMIT 1].CRM_Priority__c); } diff --git a/force-app/main/default/classes/KafkaMessageService.cls b/force-app/main/default/classes/KafkaMessageService.cls index 9b68f31e..6c8da725 100644 --- a/force-app/main/default/classes/KafkaMessageService.cls +++ b/force-app/main/default/classes/KafkaMessageService.cls @@ -23,8 +23,7 @@ public with sharing class KafkaMessageService { SELECT Id, Topic__c, SandboxOverrideTopic__c, ApexClass__c FROM KafkaMessageHandlerBinding__mdt ]) { - if(isSandbox && - String.isNotBlank(binding.SandboxOverrideTopic__c)) { + if (isSandbox && String.isNotBlank(binding.SandboxOverrideTopic__c)) { handlerBindings.put( binding.SandboxOverrideTopic__c, (IKafkaMessageConsumer) Type.forName(binding.ApexClass__c).newInstance() diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index 585523b7..1e09a8bd 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -150,7 +150,7 @@ private with sharing class KafkaPdlGtHandlerTest { Test.startTest(); handler.processMessages(kafkaMessages); Test.stopTest(); - List pl = [SELECT Id from Person__c where INT_ActorId__c = '1017419408436']; + List pl = [SELECT Id FROM Person__c WHERE INT_ActorId__c = '1017419408436']; Assert.areEqual(1, pl.size(), 'Expected one person inserted.'); } @@ -251,7 +251,7 @@ private with sharing class KafkaPdlGtHandlerTest { CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING); handleMessages(); - guy = [SELECT INT_GTDistrictNumber__c, INT_DistrictNumber__c, INT_MunicipalityNumber__c from Person__c][0]; + guy = [SELECT INT_GTDistrictNumber__c, INT_DistrictNumber__c, INT_MunicipalityNumber__c FROM Person__c][0]; Assert.areEqual('1337', guy.INT_MunicipalityNumber__c); Assert.areEqual('133769', guy.INT_GTDistrictNumber__c); Assert.areEqual('133769', guy.INT_DistrictNumber__c); @@ -263,7 +263,7 @@ private with sharing class KafkaPdlGtHandlerTest { Test.startTest(); AsyncRequestSchedulable.enqueueAsyncJobs(); // This enqueues the job. Test.stopTest(); // This runs the job. - guy = [SELECT INT_GTDistrictNumber__c, INT_DistrictNumber__c, INT_MunicipalityNumber__c from Person__c][0]; + guy = [SELECT INT_GTDistrictNumber__c, INT_DistrictNumber__c, INT_MunicipalityNumber__c FROM Person__c][0]; Assert.areEqual('2024', guy.INT_MunicipalityNumber__c); Assert.isNull(guy.INT_GTDistrictNumber__c); Assert.isNull(guy.INT_DistrictNumber__c); @@ -282,7 +282,7 @@ private with sharing class KafkaPdlGtHandlerTest { CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING); handleMessages(); - guy = [SELECT INT_GTDistrictNumber__c, INT_DistrictNumber__c, INT_MunicipalityNumber__c from Person__c][0]; + guy = [SELECT INT_GTDistrictNumber__c, INT_DistrictNumber__c, INT_MunicipalityNumber__c FROM Person__c][0]; Assert.areEqual('1337', guy.INT_MunicipalityNumber__c); insert new KafkaMessage__c( CRM_Topic__c = KafkaPdlGtHandler.GT_TOPIC, @@ -292,7 +292,7 @@ private with sharing class KafkaPdlGtHandlerTest { Test.startTest(); AsyncRequestSchedulable.enqueueAsyncJobs(); // This enqueues the job. Test.stopTest(); // This runs the job. - guy = [SELECT INT_GTDistrictNumber__c, INT_DistrictNumber__c, INT_GTMunicipalityNumber__c, INT_MunicipalityNumber__c, INT_RegionNumber__c from Person__c][0]; + guy = [SELECT INT_GTDistrictNumber__c, INT_DistrictNumber__c, INT_GTMunicipalityNumber__c, INT_MunicipalityNumber__c, INT_RegionNumber__c FROM Person__c][0]; Assert.isNull(guy.INT_GTDistrictNumber__c); Assert.isNull(guy.INT_DistrictNumber__c); Assert.isNull(guy.INT_GTMunicipalityNumber__c); @@ -362,7 +362,7 @@ private with sharing class KafkaPdlGtHandlerTest { Test.stopTest(); Assert.areEqual(KafkaMessageService.STATUS_PROCESSED, messages[0].CRM_Status__c); Assert.areEqual(KafkaMessageService.STATUS_PROCESSED, messages[1].CRM_Status__c); - Person__c[] persons = [SELECT INT_DistrictNumber__c, INT_MunicipalityNumber__c from Person__c]; + Person__c[] persons = [SELECT INT_DistrictNumber__c, INT_MunicipalityNumber__c FROM Person__c]; Assert.areEqual(1, persons.size()); Assert.areEqual('7776', persons[0].INT_MunicipalityNumber__c); Assert.isNull(persons[0].INT_DistrictNumber__c); diff --git a/force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls b/force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls index 03e9245a..6189c386 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPdAndGtHandlersTest.cls @@ -150,7 +150,7 @@ private with sharing class KafkaPdlPdAndGtHandlersTest { CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"identer":["4398046511104","68719476736"],"geografiskTilknytning":{"gtType":"BYDEL","gtKommune":null,"gtBydel":"133769","gtLand":null,"regel":"666"}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING); handleMessages(); - people = [SELECT INT_MunicipalityNumber__c from Person__c]; + people = [SELECT INT_MunicipalityNumber__c FROM Person__c]; Assert.areEqual(1, people.size()); sandvika = people[0].INT_MunicipalityNumber__c; Assert.areEqual('1337', sandvika); @@ -161,7 +161,7 @@ private with sharing class KafkaPdlPdAndGtHandlersTest { CRM_Value__c = EncodingUtil.base64Encode(Blob.valueOf('{"hentPerson":{"adressebeskyttelse":[],"bostedsadresse":[{"angittFlyttedato":"1972-09-26","gyldigFraOgMed":"1972-09-26T00:00:00","gyldigTilOgMed":null,"coAdressenavn":null,"vegadresse":{"matrikkelId":330462890,"husnummer":"54","husbokstav":null,"bruksenhetsnummer":null,"adressenavn":"Tromøy kirkevei","kommunenummer":"4203","tilleggsnavn":null,"postnummer":"4818","bydelsnummer":null,"koordinater":{"x":489639.3,"y":6478898.8,"z":null}},"matrikkeladresse":null,"ukjentBosted":null,"utenlandskAdresse":null,"folkeregistermetadata":{"ajourholdstidspunkt":"2022-01-14T15:41:39.83","gyldighetstidspunkt":"1972-09-26T00:00:00","opphoerstidspunkt":null,"kilde":"Dolly","aarsak":null,"sekvens":null},"metadata":{"opplysningsId":"582d32a7-f923-467a-9cd6-17976f6727d2","master":"FREG","endringer":[{"type":"OPPRETT","registrert":"2022-01-14T15:41:39.83","registrertAv":"Folkeregisteret","systemkilde":"FREG","kilde":"Dolly"}],"historisk":false}}],"deltBosted":[],"doedfoedtBarn":[],"doedsfall":[],"foedsel":[],"folkeregisteridentifikator":[],"folkeregisterpersonstatus":[],"forelderBarnRelasjon":[],"foreldreansvar":[],"fullmakt":[],"identitetsgrunnlag":[],"innflyttingTilNorge":[],"kjoenn":[],"kontaktadresse":[],"kontaktinformasjonForDoedsbo":[],"navn":[{"etternavn":"FORTSATTSEN"}],"opphold":[],"oppholdsadresse":[],"sikkerhetstiltak":[],"sivilstand":[],"statsborgerskap":[],"telefonnummer":[],"tilrettelagtKommunikasjon":[],"utenlandskIdentifikasjonsnummer":[],"utflyttingFraNorge":[],"vergemaalEllerFremtidsfullmakt":[]},"hentIdenter":{"identer":[{"ident":"68719476736","historisk":false,"gruppe":"FOLKEREGISTERIDENT","metadata":null,"folkeregistermetadata":null},{"ident":"4398046511104","historisk":false,"gruppe":"AKTORID","metadata":null,"folkeregistermetadata":null}]}}')), CRM_Status__c = KafkaMessageService.STATUS_PENDING); handleMessages(); - people = [SELECT INT_MunicipalityNumber__c from Person__c]; + people = [SELECT INT_MunicipalityNumber__c FROM Person__c]; Assert.areEqual(1, people.size()); sandvika = people[0].INT_MunicipalityNumber__c; Assert.areEqual('1337', sandvika); diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 9827d423..d74419fa 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -175,7 +175,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { System.Test.startTest(); handler.processMessages(kafkaMessages); System.Test.stopTest(); - List pl = [SELECT Id from Person__c where INT_ActorId__c = '2594819806563']; + List pl = [SELECT Id FROM Person__c WHERE INT_ActorId__c = '2594819806563']; Assert.areEqual(1, pl.size(), 'Expected one person inserted.'); } @@ -193,12 +193,12 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { CRM_Status__c = KafkaMessageService.STATUS_PENDING ) ); - Integer numPersonsBefore = [select id from person__c].size(); + Integer numPersonsBefore = [SELECT id FROM person__c].size(); KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); System.Test.startTest(); handler.processMessages(kafkaMessages); System.Test.stopTest(); - Assert.areEqual(numPersonsBefore, [select id from person__c].size(), + Assert.areEqual(numPersonsBefore, [SELECT id FROM person__c].size(), 'Expected none inserted.'); } @@ -655,9 +655,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { KafkaMessageService.STATUS_PROCESSED, message.CRM_Status__c, 'Expected message to be processed but it is ' + - message.CRM_Status__c + - '. CRM_ErrorMessage__c: ' + - message.CRM_ErrorMessage__c + message.CRM_Status__c + + '. CRM_ErrorMessage__c: ' + + message.CRM_ErrorMessage__c ); } @@ -1255,13 +1255,13 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { insert new List{ message1, message2, message3, message4 }; AsyncRequestSchedulable.enqueueAsyncJobs(); System.Test.stopTest(); - KafkaMessage__c[] wtf = [SELECT Id, CRM_Key__c, CRM_Status__c, CRM_ErrorMessage__c from KafkaMessage__c]; - Person__c[] all = [SELECT Id, INT_ActorId__c, INT_Confidential__c from Person__c]; - Integer n = [SELECT COUNT() from Person__c]; - Person__c fiferPerson = [SELECT Id, INT_Confidential__c from Person__c where INT_ActorId__c = '8849688496884'][0]; - Person__c fiddlerPerson = [SELECT Id, INT_Confidential__c from Person__c where INT_ActorId__c = '8154968154968'][0]; - Person__c practicalPerson = [SELECT Id, INT_Confidential__c from Person__c where INT_ActorId__c = '9471759694717'][0]; - Person__c bigBadPerson = [SELECT Id, INT_Confidential__c from Person__c where INT_ActorId__c = '9691858969185'][0]; + KafkaMessage__c[] wtf = [SELECT Id, CRM_Key__c, CRM_Status__c, CRM_ErrorMessage__c FROM KafkaMessage__c]; + Person__c[] all = [SELECT Id, INT_ActorId__c, INT_Confidential__c FROM Person__c]; + Integer n = [SELECT COUNT() FROM Person__c]; + Person__c fiferPerson = [SELECT Id, INT_Confidential__c FROM Person__c WHERE INT_ActorId__c = '8849688496884'][0]; + Person__c fiddlerPerson = [SELECT Id, INT_Confidential__c FROM Person__c WHERE INT_ActorId__c = '8154968154968'][0]; + Person__c practicalPerson = [SELECT Id, INT_Confidential__c FROM Person__c WHERE INT_ActorId__c = '9471759694717'][0]; + Person__c bigBadPerson = [SELECT Id, INT_Confidential__c FROM Person__c WHERE INT_ActorId__c = '9691858969185'][0]; Assert.areEqual('UGRADERT', fiferPerson.INT_Confidential__c); Assert.areEqual('STRENGT_FORTROLIG_UTLAND', fiddlerPerson.INT_Confidential__c); Assert.areEqual('STRENGT_FORTROLIG', practicalPerson.INT_Confidential__c); @@ -1475,8 +1475,8 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Assert.isNull(person.INT_Coordinates__c); Assert.areEqual('Testveien 1 A', person.INT_TemporaryAddress__c); Assert.areEqual('0001', person.INT_TemporaryZipCode__c); - Assert.areEqual('4321',person.INT_TemporaryMunicipalityNumber__c); - Assert.areEqual('x=354424.0, y=6862099.0, z=0.0',person.INT_TemporaryCoordinates__c); + Assert.areEqual('4321', person.INT_TemporaryMunicipalityNumber__c); + Assert.areEqual('x=354424.0, y=6862099.0, z=0.0', person.INT_TemporaryCoordinates__c); Assert.isNull(person.INT_TemporaryCountryCode__c); } @@ -1501,7 +1501,7 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { Test.stopTest(); Assert.areEqual(KafkaMessageService.STATUS_PROCESSED, messages[0].CRM_Status__c); Assert.areEqual(KafkaMessageService.STATUS_PROCESSED, messages[1].CRM_Status__c); - Person__c[] persons = [SELECT INT_FirstName__c, INT_LastName__c from Person__c]; + Person__c[] persons = [SELECT INT_FirstName__c, INT_LastName__c FROM Person__c]; Assert.areEqual(1, persons.size()); Assert.areEqual('HYDE', persons[0].INT_LastName__c); Assert.isNull(persons[0].INT_FirstName__c); From c52675ff6a1fb82a296e0cf40c121c4ab4f3dcfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20=C3=98ksnevad?= Date: Fri, 5 Jul 2024 18:17:21 +0200 Subject: [PATCH 147/159] bump prettier and prettier-plugin-apex --- .prettierrc | 1 + package-lock.json | 30 +++++++++++++----------------- package.json | 4 ++-- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/.prettierrc b/.prettierrc index 8529c324..aff6b338 100755 --- a/.prettierrc +++ b/.prettierrc @@ -1,4 +1,5 @@ { + "plugins": ["prettier-plugin-apex"], "trailingComma": "none", "printWidth": 120, "singleQuote": true, diff --git a/package-lock.json b/package-lock.json index 6ef2fd03..7f3c1142 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,8 +17,8 @@ "husky": "^8.0.3", "jest-canvas-mock": "^2.5.1", "lint-staged": "^13.2.2", - "prettier": "^2.8.8", - "prettier-plugin-apex": "^1.13.0", + "prettier": "^3.0.0", + "prettier-plugin-apex": "^2.1.0", "semver": "^7.5.1" }, "engines": { @@ -13295,42 +13295,38 @@ } }, "node_modules/prettier": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", - "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.0.tgz", + "integrity": "sha512-zBf5eHpwHOGPC47h0zrPyNn+eAEIdEzfywMoYn2XPi0P44Zp0tSq64rq0xAREh4auw2cJZHo9QUob+NqCQky4g==", "dev": true, "bin": { - "prettier": "bin-prettier.js" + "prettier": "bin/prettier.cjs" }, "engines": { - "node": ">=10.13.0" + "node": ">=14" }, "funding": { "url": "https://github.com/prettier/prettier?sponsor=1" } }, "node_modules/prettier-plugin-apex": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/prettier-plugin-apex/-/prettier-plugin-apex-1.13.0.tgz", - "integrity": "sha512-QeGHrNOR6EXoH0Mto385FDrRC+XSCc/8zvtqNvhEaFovEMC7InDp2Mn5WxjJzQUdgtUYoXL+NYcSm3nxMqsymQ==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/prettier-plugin-apex/-/prettier-plugin-apex-2.1.0.tgz", + "integrity": "sha512-km/Aqy/ZtkSkBxe8APN+ue87OA7ApL9q0mmI6ryQrVpGpcj+0ZLTiOFyR5K9t8NpTkTEvXdFuHlYmNzw9IirTw==", "dev": true, "dependencies": { - "axios": "^1.0.0", "jest-docblock": "^29.0.0", - "wait-on": "^7.0.0", - "yargs": "^17.0.0" + "wait-on": "^7.2.0" }, "bin": { "apex-ast-serializer": "vendor/apex-ast-serializer/bin/apex-ast-serializer", "apex-ast-serializer-http": "vendor/apex-ast-serializer/bin/apex-ast-serializer-http", + "install-apex-executables": "dist/bin/install-apex-executables.js", "start-apex-server": "dist/bin/start-apex-server.js", "stop-apex-server": "dist/bin/stop-apex-server.js" }, - "engines": { - "node": ">= 14.0.0" - }, "peerDependencies": { - "prettier": "^2.0.0" + "prettier": "^3.0.0" } }, "node_modules/pretty-format": { diff --git a/package.json b/package.json index 31a3f287..1be8bf3e 100644 --- a/package.json +++ b/package.json @@ -37,8 +37,8 @@ "husky": "^8.0.3", "jest-canvas-mock": "^2.5.1", "lint-staged": "^13.2.2", - "prettier": "^2.8.8", - "prettier-plugin-apex": "^1.13.0", + "prettier": "^3.0.0", + "prettier-plugin-apex": "^2.1.0", "semver": "^7.5.1" }, "husky": { From 4b457cf16ac4ccbcea6d5caa6332ac5cb3f11a89 Mon Sep 17 00:00:00 2001 From: nocturnalnematode <106680091+nocturnalnematode@users.noreply.github.com> Date: Tue, 20 Aug 2024 23:16:58 +0200 Subject: [PATCH 148/159] clarify test in KafkaMessageHandlerTest --- force-app/main/default/classes/KafkaMessageHandlerTest.cls | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/force-app/main/default/classes/KafkaMessageHandlerTest.cls b/force-app/main/default/classes/KafkaMessageHandlerTest.cls index 598c15d5..47685c26 100644 --- a/force-app/main/default/classes/KafkaMessageHandlerTest.cls +++ b/force-app/main/default/classes/KafkaMessageHandlerTest.cls @@ -6,7 +6,10 @@ public with sharing class KafkaMessageHandlerTest { /** * Tests that the topic given in SandboxOverrideTopic__c is picked up by the - * handler. + * handler. KafkaMessageHandlerBinding__mdt can not be modified in tests, so + * we assume the values are set correctly; CRM_Priority__c is set to 20 by + * default, but to 19 where the SandboxOverrideTopic__c matches the topic + * given here. */ @IsTest private static void handleSandboxOverrideTopicPriority() { From be1f62f12ce50d245afced4176853337f30274c4 Mon Sep 17 00:00:00 2001 From: nocturnalnematode <106680091+nocturnalnematode@users.noreply.github.com> Date: Tue, 20 Aug 2024 23:47:38 +0200 Subject: [PATCH 149/159] test for IsSandbox in top level of classes --- force-app/main/default/classes/KafkaMessageHandler.cls | 5 ++++- force-app/main/default/classes/KafkaMessageService.cls | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/force-app/main/default/classes/KafkaMessageHandler.cls b/force-app/main/default/classes/KafkaMessageHandler.cls index de53e5d6..84030fb3 100644 --- a/force-app/main/default/classes/KafkaMessageHandler.cls +++ b/force-app/main/default/classes/KafkaMessageHandler.cls @@ -1,4 +1,7 @@ public inherited sharing class KafkaMessageHandler extends MyTriggers { + + private final static Boolean IS_SANDBOX = [SELECT IsSandbox FROM Organization][0].IsSandbox; + /** * Finds and executes and filter class bound to the topic through KafkaMessageFilterBinding__mdt */ @@ -105,7 +108,7 @@ public inherited sharing class KafkaMessageHandler extends MyTriggers { ]) { handlerBindingByTopic.put(binding.Topic__c, binding); } - if ([SELECT IsSandbox FROM Organization][0].IsSandbox) { + if (IS_SANDBOX) { for (KafkaMessageHandlerBinding__mdt binding : [ SELECT Id, SandboxOverrideTopic__c, Priority__c, ApexJobType__c FROM KafkaMessageHandlerBinding__mdt diff --git a/force-app/main/default/classes/KafkaMessageService.cls b/force-app/main/default/classes/KafkaMessageService.cls index 6c8da725..c4d1dab6 100644 --- a/force-app/main/default/classes/KafkaMessageService.cls +++ b/force-app/main/default/classes/KafkaMessageService.cls @@ -6,7 +6,7 @@ public with sharing class KafkaMessageService { private Map handlerBindings = new Map(); private List messages; - private static Boolean isSandbox = [SELECT IsSandbox FROM Organization][0].IsSandbox; + private final static Boolean IS_SANDBOX = [SELECT IsSandbox FROM Organization][0].IsSandbox; // Before Insert constructor - takes a list of Kafka Messages that don't yet have a record id public KafkaMessageService(List messages) { @@ -23,7 +23,7 @@ public with sharing class KafkaMessageService { SELECT Id, Topic__c, SandboxOverrideTopic__c, ApexClass__c FROM KafkaMessageHandlerBinding__mdt ]) { - if (isSandbox && String.isNotBlank(binding.SandboxOverrideTopic__c)) { + if (IS_SANDBOX && String.isNotBlank(binding.SandboxOverrideTopic__c)) { handlerBindings.put( binding.SandboxOverrideTopic__c, (IKafkaMessageConsumer) Type.forName(binding.ApexClass__c).newInstance() From 72dfbb3dfa3343fe765483e9c041db0f56771c6e Mon Sep 17 00:00:00 2001 From: nocturnalnematode <106680091+nocturnalnematode@users.noreply.github.com> Date: Tue, 20 Aug 2024 23:50:34 +0200 Subject: [PATCH 150/159] clarify need for SandboxOverrideTopic__c --- force-app/main/default/classes/KafkaMessageService.cls | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/force-app/main/default/classes/KafkaMessageService.cls b/force-app/main/default/classes/KafkaMessageService.cls index c4d1dab6..c7ea8507 100644 --- a/force-app/main/default/classes/KafkaMessageService.cls +++ b/force-app/main/default/classes/KafkaMessageService.cls @@ -15,8 +15,10 @@ public with sharing class KafkaMessageService { /** * Maps each topic to its appropriate consumer. - * In prod, map every Topic__c, otherwise, let SandboxOverrideTopic__c take - * precedence. + * In prod, map every Topic__c. + * In dev, when the topic differs from that in prod, e.g. foo.bar-q2 instead + * of foo.bar, this topic is specified in SandboxOverrideTopic__c, which + * then takes precedence. */ private void setupHandlerBindings() { for (KafkaMessageHandlerBinding__mdt binding : [ From d3b98b112d966360415653394a1c26d08d30eb26 Mon Sep 17 00:00:00 2001 From: nocturnalnematode <106680091+nocturnalnematode@users.noreply.github.com> Date: Tue, 20 Aug 2024 23:58:36 +0200 Subject: [PATCH 151/159] clarify constants --- force-app/pdl-handler/classes/KafkaPdlGtHandler.cls | 2 +- force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index 67591f9c..85310c62 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -5,7 +5,7 @@ */ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer { - public static String GT_TOPIC = KafkaMessageHandlerBinding__mdt.getInstance('PdlGeografiskTilknytning').Topic__c; + public final static String GT_TOPIC = KafkaMessageHandlerBinding__mdt.getInstance('PdlGeografiskTilknytning').Topic__c; private LoggerUtility logger = new LoggerUtility('PDL'); diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index 9cd66f1a..b1ed5810 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -5,7 +5,7 @@ */ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMessageConsumer { - public static String PD_TOPIC = ( + public final static String PD_TOPIC = ( [SELECT IsSandbox FROM Organization][0].IsSandbox ? KafkaMessageHandlerBinding__mdt.getInstance('PdlPersondokumentHandler').SandboxOverrideTopic__c : KafkaMessageHandlerBinding__mdt.getInstance('PdlPersondokumentHandler').Topic__c); From 063d93e831ac02daf111a3b85e4e79c76449968b Mon Sep 17 00:00:00 2001 From: nocturnalnematode <106680091+nocturnalnematode@users.noreply.github.com> Date: Wed, 21 Aug 2024 00:00:00 +0200 Subject: [PATCH 152/159] clarify assignIdent --- .../pdl-handler/classes/KafkaPdlGtHandler.cls | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index 85310c62..d0ad077a 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -9,16 +9,20 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer private LoggerUtility logger = new LoggerUtility('PDL'); - private void assignIdent(Person__c p, String s) { - if(s.length() == 13) { - p.INT_ActorId__c = s; - } else if(s.length() == 11) { - if(Integer.valueOf(s.left(1)) >= 4) { - p.INT_dnr__c = s; + /** + * Assigns FNR, DNR, or actor id based on what sort of ident is used. + * Also assigns Name when FNR or DNR. + */ + private void assignIdent(Person__c p, String ident) { + if(ident.length() == 13) { + p.INT_ActorId__c = ident; + } else if(ident.length() == 11) { + if(Integer.valueOf(ident.left(1)) >= 4) { + p.INT_dnr__c = ident; } else { - p.INT_fnr__c = s; + p.INT_fnr__c = ident; } - p.Name = s; // flows to Account.INT_PersonIdent__c + p.Name = ident; // flows to Account.INT_PersonIdent__c } else { throw new PdlGtException('Unrecognised ident.'); } @@ -63,8 +67,8 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer */ private Person__c personFromKafkaPerson(KafkaPersonGT kafkaPerson) { Person__c person = new Person__c(); - for(String s : kafkaPerson.identer) { - assignIdent(person, s); + for(String ident : kafkaPerson.identer) { + assignIdent(person, ident); } nullOutFields(person); PdlGeografiskTilknytning gt = kafkaPerson.geografiskTilknytning; From 5550f9cbc434ec46728402d355c250d2cf79090e Mon Sep 17 00:00:00 2001 From: nocturnalnematode <106680091+nocturnalnematode@users.noreply.github.com> Date: Wed, 21 Aug 2024 00:12:03 +0200 Subject: [PATCH 153/159] expand non-loop single character variables --- .../pdl-handler/classes/KafkaPdlGtHandler.cls | 48 +++++++++---------- .../classes/KafkaPdlGtHandlerTest.cls | 28 +++++------ .../classes/KafkaPdlPersondokumentHandler.cls | 38 +++++++-------- .../KafkaPdlPersondokumentHandlerTest.cls | 34 ++++++------- 4 files changed, 74 insertions(+), 74 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index d0ad077a..77ce954d 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -13,16 +13,16 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer * Assigns FNR, DNR, or actor id based on what sort of ident is used. * Also assigns Name when FNR or DNR. */ - private void assignIdent(Person__c p, String ident) { + private void assignIdent(Person__c person, String ident) { if(ident.length() == 13) { - p.INT_ActorId__c = ident; + person.INT_ActorId__c = ident; } else if(ident.length() == 11) { if(Integer.valueOf(ident.left(1)) >= 4) { - p.INT_dnr__c = ident; + person.INT_dnr__c = ident; } else { - p.INT_fnr__c = ident; + person.INT_fnr__c = ident; } - p.Name = ident; // flows to Account.INT_PersonIdent__c + person.Name = ident; // flows to Account.INT_PersonIdent__c } else { throw new PdlGtException('Unrecognised ident.'); } @@ -31,32 +31,32 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer /** * Nulls what may have been set before. */ - private static void nullOutFields(Person__c p) { - p.INT_GTDistrictNumber__c = null; - p.INT_GTMunicipalityNumber__c = null; - p.INT_DistrictNumber__c = null; - p.INT_MunicipalityNumber__c = null; - p.INT_RegionNumber__c = null; + private static void nullOutFields(Person__c person) { + person.INT_GTDistrictNumber__c = null; + person.INT_GTMunicipalityNumber__c = null; + person.INT_DistrictNumber__c = null; + person.INT_MunicipalityNumber__c = null; + person.INT_RegionNumber__c = null; } /** * District includes all the data we need. */ - private static void setFieldsFromDistrict(Person__c p, PdlGeografiskTilknytning gt) { - p.INT_GTDistrictNumber__c = gt.gtBydel; - p.INT_GTMunicipalityNumber__c = gt.gtBydel.left(4); - p.INT_DistrictNumber__c = p.INT_GTDistrictNumber__c; - p.INT_MunicipalityNumber__c = p.INT_GTMunicipalityNumber__c; - p.INT_RegionNumber__c = gt.gtBydel.left(2); + private static void setFieldsFromDistrict(Person__c person, PdlGeografiskTilknytning gt) { + person.INT_GTDistrictNumber__c = gt.gtBydel; + person.INT_GTMunicipalityNumber__c = gt.gtBydel.left(4); + person.INT_DistrictNumber__c = person.INT_GTDistrictNumber__c; + person.INT_MunicipalityNumber__c = person.INT_GTMunicipalityNumber__c; + person.INT_RegionNumber__c = gt.gtBydel.left(2); } /** * Municipality does not set the district. */ - private static void setFieldsFromMunicipality(Person__c p, PdlGeografiskTilknytning gt) { - p.INT_GTMunicipalityNumber__c = gt.gtKommune; - p.INT_MunicipalityNumber__c = p.INT_GTMunicipalityNumber__c; - p.INT_RegionNumber__c = gt.gtKommune.left(2); + private static void setFieldsFromMunicipality(Person__c person, PdlGeografiskTilknytning gt) { + person.INT_GTMunicipalityNumber__c = gt.gtKommune; + person.INT_MunicipalityNumber__c = person.INT_GTMunicipalityNumber__c; + person.INT_RegionNumber__c = gt.gtKommune.left(2); } /** @@ -156,13 +156,13 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer Map messageFromActorId = new Map(); for (KafkaMessage__c msg : messages) { if (msg.CRM_Status__c == KafkaMessageService.STATUS_PENDING) { - Person__c p = createPersonRecord(msg); + Person__c person = createPersonRecord(msg); // Ensure that a System User is set as Owner if even if message // processing is manually retried by an administrator user if (KafkaIntegrationCustomSetting.integrationUserId != null) { - p.OwnerId = KafkaIntegrationCustomSetting.integrationUserId; + person.OwnerId = KafkaIntegrationCustomSetting.integrationUserId; } - personFromActorId.put(msg.CRM_Key__c, p); + personFromActorId.put(msg.CRM_Key__c, person); messageFromActorId.put(msg.CRM_Key__c, msg); // set to processed; to be changed if upsert fails msg.CRM_Status__c = KafkaMessageService.STATUS_PROCESSED; diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index 1e09a8bd..7953904d 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -162,8 +162,8 @@ private with sharing class KafkaPdlGtHandlerTest { createAndInsertBaseKafkaPerson('4398046511104', '68719476736'); Test.startTest(); Test.stopTest(); - Person__c[] ps = [SELECT INT_ActorId__c FROM Person__c]; - Assert.areEqual('4398046511104', ps[0].INT_ActorId__c); + Person__c[] people = [SELECT INT_ActorId__c FROM Person__c]; + Assert.areEqual('4398046511104', people[0].INT_ActorId__c); } /** @@ -172,10 +172,10 @@ private with sharing class KafkaPdlGtHandlerTest { @IsTest static void setGTFromKommunenummer() { createAndInsertBaseKafkaPerson('4398046511104', '68719476736'); - Person__c[] ps = [SELECT INT_ActorId__c, INT_GTMunicipalityNumber__c FROM Person__c]; - Assert.areEqual(1, ps.size()); - Person__c p = ps[0]; - Assert.isNull(p.INT_GTMunicipalityNumber__c); + Person__c[] people = [SELECT INT_ActorId__c, INT_GTMunicipalityNumber__c FROM Person__c]; + Assert.areEqual(1, people.size()); + Person__c person = people[0]; + Assert.isNull(person.INT_GTMunicipalityNumber__c); List kafkaMessages = new List(); kafkaMessages.add( new KafkaMessage__c( @@ -189,12 +189,12 @@ private with sharing class KafkaPdlGtHandlerTest { Test.startTest(); handler.processMessages(kafkaMessages); Test.stopTest(); - ps = [SELECT INT_ActorId__c, INT_GTMunicipalityNumber__c, INT_MunicipalityNumber__c, INT_RegionNumber__c FROM Person__c]; - Assert.areEqual(1, ps.size()); - p = ps[0]; - Assert.areEqual('1337', p.INT_GTMunicipalityNumber__c); - Assert.areEqual('1337', p.INT_MunicipalityNumber__c); - Assert.areEqual('13', p.INT_RegionNumber__c); + people = [SELECT INT_ActorId__c, INT_GTMunicipalityNumber__c, INT_MunicipalityNumber__c, INT_RegionNumber__c FROM Person__c]; + Assert.areEqual(1, people.size()); + person = people[0]; + Assert.areEqual('1337', person.INT_GTMunicipalityNumber__c); + Assert.areEqual('1337', person.INT_MunicipalityNumber__c); + Assert.areEqual('13', person.INT_RegionNumber__c); } /** @@ -322,8 +322,8 @@ private with sharing class KafkaPdlGtHandlerTest { Person__c[] persons = new Person__c[]{}; KafkaPdlGtHandler handler = new KafkaPdlGtHandler(); for (KafkaMessage__c msg : messages) { - Person__c p = handler.createPersonRecord(msg); - persons.add(p); + Person__c person = handler.createPersonRecord(msg); + persons.add(person); msg.CRM_Status__c = KafkaMessageService.STATUS_PROCESSED; } // mess up one of our persons by exceeding the max length of one of its diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index b1ed5810..f70516d8 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -382,25 +382,25 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * Sets municipality and/or district number. * Prioritize GT, only use the hentPerson address if there is no better * source. - * @param p person to be inserted + * @param person person to be inserted * @param gtPerson existing person, may be null */ - private void setMunicipalityAndOrDistrict(Person__c p, Person__c gtPerson) { + private void setMunicipalityAndOrDistrict(Person__c person, Person__c gtPerson) { if (gtPerson?.INT_GTDistrictNumber__c != null) { logger.info('setting municipality and district from gt district', null); - p.INT_GTDistrictNumber__c = gtPerson.INT_GTDistrictNumber__c; - p.INT_DistrictNumber__c = p.INT_GTDistrictNumber__c; - p.INT_MunicipalityNumber__c = p.INT_GTDistrictNumber__c.left(4); + person.INT_GTDistrictNumber__c = gtPerson.INT_GTDistrictNumber__c; + person.INT_DistrictNumber__c = person.INT_GTDistrictNumber__c; + person.INT_MunicipalityNumber__c = person.INT_GTDistrictNumber__c.left(4); } else if (gtPerson?.INT_GTMunicipalityNumber__c != null) { logger.info('setting municipality from gt municipality', null); - p.INT_GTMunicipalityNumber__c = gtPerson.INT_GTMunicipalityNumber__c; - p.INT_MunicipalityNumber__c = p.INT_GTMunicipalityNumber__c; + person.INT_GTMunicipalityNumber__c = gtPerson.INT_GTMunicipalityNumber__c; + person.INT_MunicipalityNumber__c = person.INT_GTMunicipalityNumber__c; } else { logger.info('setting municipality and district from hentPerson', null); - p.INT_DistrictNumber__c = p.INT_AddressDistrictNumber__c; - p.INT_MunicipalityNumber__c = p.INT_AddressMunicipalityNumber__c; + person.INT_DistrictNumber__c = person.INT_AddressDistrictNumber__c; + person.INT_MunicipalityNumber__c = person.INT_AddressMunicipalityNumber__c; } } @@ -612,15 +612,15 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess } } - private static void assignFnrIfAppropriate(Person__c p, PdlFolkeregisteridentifikator id) { - if (id.type == PDL_IdentType.FNR && !id.metadata.historisk && id.status == PDL_IdentStatus.I_BRUK) { - p.INT_fnr__c = id.identifikasjonsnummer; + private static void assignFnrIfAppropriate(Person__c person, PdlFolkeregisteridentifikator ident) { + if (ident.type == PDL_IdentType.FNR && !ident.metadata.historisk && ident.status == PDL_IdentStatus.I_BRUK) { + person.INT_fnr__c = ident.identifikasjonsnummer; } } - private static void assignDnrIfAppropriate(Person__c p, PdlFolkeregisteridentifikator id) { - if (id.type == PDL_IdentType.DNR && (String.isBlank(p.INT_dnr__c) || !id.metadata.historisk)) { - p.INT_dnr__c = id.identifikasjonsnummer; + private static void assignDnrIfAppropriate(Person__c person, PdlFolkeregisteridentifikator ident) { + if (ident.type == PDL_IdentType.DNR && (String.isBlank(person.INT_dnr__c) || !ident.metadata.historisk)) { + person.INT_dnr__c = ident.identifikasjonsnummer; } } @@ -631,10 +631,10 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess Person__c person, PdlFolkeregisteridentifikator[] identifiers ) { - for (PdlFolkeregisteridentifikator id : identifiers) { - if (String.isNotBlank(id.identifikasjonsnummer)) { // when is this blank? - assignFnrIfAppropriate(person, id); - assignDnrIfAppropriate(person, id); + for (PdlFolkeregisteridentifikator ident : identifiers) { + if (String.isNotBlank(ident.identifikasjonsnummer)) { // when is this blank? + assignFnrIfAppropriate(person, ident); + assignDnrIfAppropriate(person, ident); } } } diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index d74419fa..810c1903 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -193,12 +193,12 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { CRM_Status__c = KafkaMessageService.STATUS_PENDING ) ); - Integer numPersonsBefore = [SELECT id FROM person__c].size(); + Integer numPersonsBefore = [SELECT Id FROM person__c].size(); KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); System.Test.startTest(); handler.processMessages(kafkaMessages); System.Test.stopTest(); - Assert.areEqual(numPersonsBefore, [SELECT id FROM person__c].size(), + Assert.areEqual(numPersonsBefore, [SELECT Id FROM person__c].size(), 'Expected none inserted.'); } @@ -611,18 +611,18 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { 1, [SELECT COUNT() FROM KafkaMessage__c WHERE CRM_Status__c = :KafkaMessageService.STATUS_PROCESSED] ); - Person__c p = [ + Person__c person = [ SELECT Id, INT_ActorId__c, INT_fnr__c, Name, INT_IsHasTombstone__c, INT_FirstName__c, INT_LastName__c FROM Person__c LIMIT 1 ]; // Assert that only tombstone and id fields has values - Assert.areEqual('1000012345678', p.INT_ActorId__c, 'ActorId'); - Assert.areEqual('12345678901', p.INT_fnr__c, 'fnr'); - Assert.areEqual('12345678901', p.Name, 'Name'); - Assert.areEqual(true, p.INT_IsHasTombstone__c, 'Tombstone'); - Assert.areEqual(null, p.INT_FirstName__c, 'Firstname'); - Assert.areEqual(null, p.INT_LastName__c, 'Lastname'); + Assert.areEqual('1000012345678', person.INT_ActorId__c, 'ActorId'); + Assert.areEqual('12345678901', person.INT_fnr__c, 'fnr'); + Assert.areEqual('12345678901', person.Name, 'Name'); + Assert.areEqual(true, person.INT_IsHasTombstone__c, 'Tombstone'); + Assert.areEqual(null, person.INT_FirstName__c, 'Firstname'); + Assert.areEqual(null, person.INT_LastName__c, 'Lastname'); } /******************************** @@ -1417,11 +1417,11 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); handler.processMessages(kafkaMessages); System.Test.stopTest(); - Person__c p = [SELECT Id, INT_ResidentialZipCode__c, INT_AddressMunicipalityNumber__c, INT_AddressDistrictNumber__c, INT_Coordinates__c FROM Person__c][0]; - Assert.areEqual('4096', p.INT_ResidentialZipCode__c); - Assert.areEqual('8192', p.INT_AddressMunicipalityNumber__c); - Assert.areEqual('262144', p.INT_AddressDistrictNumber__c); - Assert.areEqual('x=4806741.0, y=1286234.0, z=-1.0', p.INT_Coordinates__c); + Person__c person = [SELECT Id, INT_ResidentialZipCode__c, INT_AddressMunicipalityNumber__c, INT_AddressDistrictNumber__c, INT_Coordinates__c FROM Person__c][0]; + Assert.areEqual('4096', person.INT_ResidentialZipCode__c); + Assert.areEqual('8192', person.INT_AddressMunicipalityNumber__c); + Assert.areEqual('262144', person.INT_AddressDistrictNumber__c); + Assert.areEqual('x=4806741.0, y=1286234.0, z=-1.0', person.INT_Coordinates__c); } /** @@ -1442,9 +1442,9 @@ private with sharing class KafkaPdlPersondokumentHandlerTest { KafkaPdlPersondokumentHandler handler = new KafkaPdlPersondokumentHandler(); handler.processMessages(kafkaMessages); System.Test.stopTest(); - Person__c p = [SELECT Id, INT_ActorId__c, INT_ResidentialZipCode__c, INT_AddressMunicipalityNumber__c, INT_AddressDistrictNumber__c, INT_Coordinates__c FROM Person__c][0]; - Assert.areEqual('9011710145110', p.INT_ActorId__c); - Assert.isNull(p.INT_ResidentialZipCode__c); + Person__c person = [SELECT Id, INT_ActorId__c, INT_ResidentialZipCode__c, INT_AddressMunicipalityNumber__c, INT_AddressDistrictNumber__c, INT_Coordinates__c FROM Person__c][0]; + Assert.areEqual('9011710145110', person.INT_ActorId__c); + Assert.isNull(person.INT_ResidentialZipCode__c); } /** From 3d16bcee13a7f41fc91ade95e198d192d1568027 Mon Sep 17 00:00:00 2001 From: nocturnalnematode <106680091+nocturnalnematode@users.noreply.github.com> Date: Wed, 21 Aug 2024 00:15:54 +0200 Subject: [PATCH 154/159] clarify method names --- force-app/pdl-handler/classes/KafkaPdlGtHandler.cls | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls index 77ce954d..182d3ded 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandler.cls @@ -31,7 +31,7 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer /** * Nulls what may have been set before. */ - private static void nullOutFields(Person__c person) { + private static void nullOutAddressFields(Person__c person) { person.INT_GTDistrictNumber__c = null; person.INT_GTMunicipalityNumber__c = null; person.INT_DistrictNumber__c = null; @@ -42,7 +42,7 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer /** * District includes all the data we need. */ - private static void setFieldsFromDistrict(Person__c person, PdlGeografiskTilknytning gt) { + private static void setAddressFromDistrict(Person__c person, PdlGeografiskTilknytning gt) { person.INT_GTDistrictNumber__c = gt.gtBydel; person.INT_GTMunicipalityNumber__c = gt.gtBydel.left(4); person.INT_DistrictNumber__c = person.INT_GTDistrictNumber__c; @@ -53,7 +53,7 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer /** * Municipality does not set the district. */ - private static void setFieldsFromMunicipality(Person__c person, PdlGeografiskTilknytning gt) { + private static void setAddressFromMunicipality(Person__c person, PdlGeografiskTilknytning gt) { person.INT_GTMunicipalityNumber__c = gt.gtKommune; person.INT_MunicipalityNumber__c = person.INT_GTMunicipalityNumber__c; person.INT_RegionNumber__c = gt.gtKommune.left(2); @@ -70,16 +70,16 @@ public without sharing class KafkaPdlGtHandler implements IKafkaMessageConsumer for(String ident : kafkaPerson.identer) { assignIdent(person, ident); } - nullOutFields(person); + nullOutAddressFields(person); PdlGeografiskTilknytning gt = kafkaPerson.geografiskTilknytning; if (gt.gtType == 'BYDEL') { // TODO: figure out exactly what sort of granularity we want when // logging branching logger.info('Setting GT from district', null); - setFieldsFromDistrict(person, gt); + setAddressFromDistrict(person, gt); } else if (gt.gtType == 'KOMMUNE') { logger.info('Setting GT from municipality, clearing district fields', null); - setFieldsFromMunicipality(person, gt); + setAddressFromMunicipality(person, gt); } else if (gt.gtType == 'UDEFINERT') { logger.info('Not setting GT from UDEFINERT, clearing all GT fields', null); } else if (gt.gtType == 'UTLAND') { From 9b6c5bfaeb08bcf47d0984fb9bb76c68e5e8c0ca Mon Sep 17 00:00:00 2001 From: nocturnalnematode <106680091+nocturnalnematode@users.noreply.github.com> Date: Wed, 21 Aug 2024 00:26:09 +0200 Subject: [PATCH 155/159] trim unnecessary sharing rules --- force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls | 2 +- .../pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index 7953904d..b8cc40c1 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -4,7 +4,7 @@ * against persons inserted using that. */ @IsTest -private with sharing class KafkaPdlGtHandlerTest { +private class KafkaPdlGtHandlerTest { /** * Sends kafka messages. like KafkaMessageAsyncJob but without the async diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 810c1903..0b6d4395 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -1,5 +1,5 @@ @IsTest -private with sharing class KafkaPdlPersondokumentHandlerTest { +private class KafkaPdlPersondokumentHandlerTest { /** * Creates data we would otherwise fetch; common codes, and so on. From af86150a91ba4988a04ec709f0f1ea9e628f5366 Mon Sep 17 00:00:00 2001 From: nocturnalnematode <106680091+nocturnalnematode@users.noreply.github.com> Date: Wed, 21 Aug 2024 00:34:10 +0200 Subject: [PATCH 156/159] cleanup --- .../KafkaPdlPersondokumentHandlerTest.cls | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 0b6d4395..88390e9c 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -206,13 +206,13 @@ private class KafkaPdlPersondokumentHandlerTest { * TESTS FOR IDENTS * *******************************************/ - @isTest /** * Tests that person's Name is set to FOLKEREGISTERIDENT when both * FOLKEREGISTERIDENT and NPID exist and are not historic. * Also tests that Name is set to NPID when the FOLKEREGISTERIDENT exists * but is historic. */ + @isTest static void setNameFieldTest() { KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); @@ -247,11 +247,11 @@ private class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('12345678911', person.Name, 'Expected non historisk NPID'); } - @IsTest /** * Tests that person's Name is not set and instead an exception is thrown * when FOLKEREGISTERIDENT and NPID exist but are historic. */ + @IsTest static void setNameFieldException() { KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); @@ -287,11 +287,11 @@ private class KafkaPdlPersondokumentHandlerTest { System.Test.stopTest(); } - @IsTest /** * Create a person with an (active) FNR and an (inactive) DNR, ensure both * are set. */ + @IsTest static void setIdentsTest() { KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); @@ -661,10 +661,10 @@ private class KafkaPdlPersondokumentHandlerTest { ); } - @isTest /** * Create, insert, and process a message. */ + @isTest static void insertKafkaMessageDefault() { KafkaPerson3 kafkaPerson = createBaseKafkaPerson('1122334455666'); PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); @@ -703,11 +703,11 @@ private class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('1122334455666', person.INT_actorId__c, 'Expected AKTØRID to be set'); } - @isTest /** * All this method seems to test is that persons are not updated when * there exists a (processed) tombstone with the same ident. */ + @isTest static void insertKafkaMessageProcessed() { KafkaPerson3 athos = createBaseKafkaPerson('1122334455666'); PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); @@ -771,12 +771,12 @@ private class KafkaPdlPersondokumentHandlerTest { Assert.areEqual(0, [SELECT COUNT() FROM Person__c WHERE Name = '12345678901']); } - @isTest /** * Forces and catches nullpointerexception caused by attempting to create a * security measure with nonexistent INT_ValidFromDate__c. Catching this * exception should create the warning from the method name. */ + @isTest static void insertKafkaMessageWarning() { KafkaPerson3 laurel = createBaseKafkaPerson('1122334455666'); PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); @@ -837,10 +837,10 @@ private class KafkaPdlPersondokumentHandlerTest { Assert.areEqual(0, [SELECT COUNT() FROM Person__c WHERE Name = '12345678901']); } - @isTest /** * TODO: check what exactly this tests */ + @isTest static void insertKafkaMessageUpdateError() { insert new Person__c( Name = '12345678901', @@ -974,13 +974,13 @@ private class KafkaPdlPersondokumentHandlerTest { Assert.areEqual('1122334455666', person.INT_actorId__c, 'Expected AKTØRID to be set'); } - @isTest /** * Check that: * - person with npid is inserted normally, gets name = npid * - giving this person a dnr sets name = dnr * - deprecating the dnr and adding fnr sets name = fnr */ + @isTest static void insertKafkaMessageNpidPersonFromNpidToFnr() { KafkaPerson3 kafkaPerson = createBaseKafkaPerson('1122334455666'); PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); From 1a6442e54d24d378a3f4c84724d23e840a7bdadd Mon Sep 17 00:00:00 2001 From: nocturnalnematode <106680091+nocturnalnematode@users.noreply.github.com> Date: Wed, 21 Aug 2024 00:34:21 +0200 Subject: [PATCH 157/159] minor --- force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls | 1 + 1 file changed, 1 insertion(+) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls index f70516d8..180620ed 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandler.cls @@ -63,6 +63,7 @@ public without sharing class KafkaPdlPersondokumentHandler implements IKafkaMess * distinguished by a _null_ message value. * @param messages Set of Kafka Messages in scope * @return Deduplicated set of Kafka Message + * @see KafkaMessageService */ @TestVisible private void checkLastUpdatedAndTombStones(List messages) { From 6c1b4352b936dcc91ce2163ec398523d271c13b3 Mon Sep 17 00:00:00 2001 From: nocturnalnematode <106680091+nocturnalnematode@users.noreply.github.com> Date: Mon, 9 Sep 2024 10:24:14 +0200 Subject: [PATCH 158/159] rename tests --- .../classes/KafkaPdlGtHandlerTest.cls | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls index b8cc40c1..3085239b 100644 --- a/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlGtHandlerTest.cls @@ -155,10 +155,11 @@ private class KafkaPdlGtHandlerTest { } /** - * Tests that we can insert a basic person for further testing. + * Tests that a person can be created from a persondokument. This lets us + * write terse test methods below. */ @isTest - static void testCreatePersonFromPersonDocument() { + static void personCanBeCreatedFromPersonDocument() { createAndInsertBaseKafkaPerson('4398046511104', '68719476736'); Test.startTest(); Test.stopTest(); @@ -170,7 +171,7 @@ private class KafkaPdlGtHandlerTest { * Tests setting GT for existing person. */ @IsTest - static void setGTFromKommunenummer() { + static void geografiskTilknytningIsSetCorrectlyForExistingPerson() { createAndInsertBaseKafkaPerson('4398046511104', '68719476736'); Person__c[] people = [SELECT INT_ActorId__c, INT_GTMunicipalityNumber__c FROM Person__c]; Assert.areEqual(1, people.size()); @@ -202,7 +203,7 @@ private class KafkaPdlGtHandlerTest { * https://pdl-docs.intern.nav.no/ekstern/index.html#geografisk-tilknytning */ @IsTest - static void setGTFromBydel() { + static void geografiskTilknytningIsSetCorrectlyForExistingPersonFromDistrictNumber() { createAndInsertBaseKafkaPerson('4398046511104', '68719476736'); KafkaPdlGtHandler handler = new KafkaPdlGtHandler(); Test.startTest(); @@ -242,7 +243,7 @@ private class KafkaPdlGtHandlerTest { * lower precision. */ @IsTest - static void setMunicipalityAfterDistrict() { + static void clearDistrictWhenSettingMunicipality() { Person__c guy; // Give our guy the highest precision (district) insert new KafkaMessage__c( @@ -273,7 +274,7 @@ private class KafkaPdlGtHandlerTest { * Tests that nothing remains of the old GT when inserting UDEFINERT. */ @IsTest - static void setUndefinedAfterDistrict() { + static void clearEverythingWhenSettingUdefinert() { Person__c guy; // Give our guy the highest precision (district) insert new KafkaMessage__c( @@ -305,7 +306,7 @@ private class KafkaPdlGtHandlerTest { * the DML fails on one of them. */ @IsTest - static void testPartialUpsert() { + static void batchWithBadMessageResultsInPartialUpsert() { // two valid messages KafkaMessage__c[] messages = new KafkaMessage__c[]{ new KafkaMessage__c( @@ -343,7 +344,7 @@ private class KafkaPdlGtHandlerTest { * values sent in the last message. */ @IsTest - static void testDuplicateKeys() { + static void onlyLastMessageIsUsedWhenReceivingMultipleWithSameKey() { // two different messages with the same key KafkaMessage__c[] messages = new KafkaMessage__c[]{ new KafkaMessage__c( From 9896be1914b63df1476ee0238f4b6f1530769e48 Mon Sep 17 00:00:00 2001 From: nocturnalnematode <106680091+nocturnalnematode@users.noreply.github.com> Date: Tue, 10 Sep 2024 18:02:18 +0200 Subject: [PATCH 159/159] rename, and clarify comments for, persondok-tests --- .../KafkaPdlPersondokumentHandlerTest.cls | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls index 88390e9c..9f5ba433 100644 --- a/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls +++ b/force-app/pdl-handler/classes/KafkaPdlPersondokumentHandlerTest.cls @@ -161,7 +161,7 @@ private class KafkaPdlPersondokumentHandlerTest { * Test for a typical Dolly person */ @isTest - static void testCreatePersonFromPersonDokument() { + static void typicalPersondokumentResultsInNewPerson() { List kafkaMessages = new List(); kafkaMessages.add( new KafkaMessage__c( @@ -183,7 +183,7 @@ private class KafkaPdlPersondokumentHandlerTest { * Simple test to ensure tombstones (null values) do not result in a person */ @isTest - static void testTombstoneIsNotInserted() { + static void tombstoneDoesNotResultInNewPerson() { List kafkaMessages = new List(); kafkaMessages.add( new KafkaMessage__c( @@ -213,7 +213,7 @@ private class KafkaPdlPersondokumentHandlerTest { * but is historic. */ @isTest - static void setNameFieldTest() { + static void correctIdentIsUsedForNameField() { KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); Integer i = kPerson.hentIdenter.identer.size() - 1; @@ -252,7 +252,7 @@ private class KafkaPdlPersondokumentHandlerTest { * when FOLKEREGISTERIDENT and NPID exist but are historic. */ @IsTest - static void setNameFieldException() { + static void throw_PdlIdentException_When_OnlyHistoricIdentsExist() { KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); kPerson.hentIdenter.identer.add(new PDL_IdentInformasjon()); Integer i = kPerson.hentIdenter.identer.size() - 1; @@ -292,7 +292,7 @@ private class KafkaPdlPersondokumentHandlerTest { * are set. */ @IsTest - static void setIdentsTest() { + static void setFnrWhenActiveAndDnrWhenInactive() { KafkaPerson3 kPerson = createBaseKafkaPerson('1234567890123'); PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); identInfo.ident = '12345678901'; @@ -343,7 +343,7 @@ private class KafkaPdlPersondokumentHandlerTest { * KafkaMessage__c.CRM_Status__c should be set to error */ @IsTest - static void checkLastUpdatedAndTombStonesOlderMessages() { + static void when_MessageIsOlderThanLastmodifieddate_Expect_Warning() { Person__c person1 = new Person__c(); person1.INT_ActorId__c = '1000012345678'; person1.Name = '20000000000'; @@ -372,7 +372,7 @@ private class KafkaPdlPersondokumentHandlerTest { * KafkaMessage__c.CRM_Status__c should not be updated */ @IsTest - static void checkLastUpdatedAndTombStonesNewMessagesNoLastUpdated() { + static void when_LastUpdatedFromPDL_isNull_DoNotInvalidateMessage() { Person__c person1 = new Person__c(); person1.INT_ActorId__c = '1000012345678'; person1.Name = '20000000000'; @@ -397,11 +397,11 @@ private class KafkaPdlPersondokumentHandlerTest { /* SCENARIO: * A Person exists in Salesforce and we try to process a KafkaMessage__c - * where the CreatedDate is after than the Person INT_LastUpdatedFromPDL__c + * where the CreatedDate is newer than the Person INT_LastUpdatedFromPDL__c * KafkaMessage__c.CRM_Status__c should not be updated */ @IsTest - static void checkLastUpdatedAndTombStonesNewMessages() { + static void when_MessageIsNewerThanPerson_DoNotInvalidateMessage() { Person__c person1 = new Person__c(); person1.INT_ActorId__c = '1000012345678'; person1.Name = '20000000000'; @@ -430,7 +430,7 @@ private class KafkaPdlPersondokumentHandlerTest { * KafkaMessage__c.CRM_Status__c should not be updated */ @IsTest - static void checkLastUpdatedAndTombStonesBrandNewMessages() { + static void when_PersonDoesNotYetExist_DoNotInvalidateMessage() { String createdDate = Datetime.now().addDays(2).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); KafkaMessage__c msg = (KafkaMessage__c) JSON.deserializeStrict( '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + @@ -450,10 +450,10 @@ private class KafkaPdlPersondokumentHandlerTest { /* SCENARIO: * We try to process several KafkaMessage__c where they all have the same * key and matches a Person in Salesforce - * KafkaMessage__c.CRM_Status__c should be set to processec on only the oldest + * KafkaMessage__c.CRM_Status__c should be set to warning on only the oldest */ @IsTest - static void checkLastUpdatedAndTombStonesNewDuplicateMessages() { + static void when_MultipleMessagesHaveSameKey_WarnOnTheOldestAndDoNothingWithTheRest() { Person__c person1 = new Person__c(); person1.INT_ActorId__c = '1000012345678'; person1.Name = '20000000000'; @@ -513,10 +513,10 @@ private class KafkaPdlPersondokumentHandlerTest { /* SCENARIO: * We try to process two several KafkaMessage__c where they all have the * same actorId that matches a Person in Salesforce, but one is a tombstone - * Both KafkaMessage__c should be processed + * Don't process the first one. */ @IsTest - static void checkLastUpdatedAndTombStonesDuplicateMessagesWithTombstone() { + static void when_OneMessageIsNotTombstoneAndOneIs_SkipUpdateForTheFirst() { Person__c person1 = new Person__c(); person1.INT_ActorId__c = '1000012345678'; person1.Name = '20000000000'; @@ -557,7 +557,7 @@ private class KafkaPdlPersondokumentHandlerTest { * KafkaMessage__c.CRM_Status__c should be set to processed */ @IsTest - static void checkLastUpdatedAndTombStonesBrandNewMessagesWithTombstone() { + static void when_PersonDoesNotExistAndMessageIsTombstone_SkipInsert() { String createdDate1 = Datetime.now().addDays(1).format('yyyy-MM-dd\'T\'HH:mm:ss.SSSZ'); KafkaMessage__c msg1 = (KafkaMessage__c) JSON.deserializeStrict( '{"attributes":{"type":"KafkaMessage__c"}, "CreatedDate":"' + @@ -581,7 +581,7 @@ private class KafkaPdlPersondokumentHandlerTest { * Person should get a tombstone */ @IsTest - static void processTombstoneTest() { + static void when_PersonExistsAndMessageIsTombstone_GivePersonTombstone() { insert new Person__c( Name = '12345678901', INT_fnr__c = '12345678901', @@ -665,7 +665,7 @@ private class KafkaPdlPersondokumentHandlerTest { * Create, insert, and process a message. */ @isTest - static void insertKafkaMessageDefault() { + static void identFieldsAreSetAsExpectedFromMinimalMessage() { KafkaPerson3 kafkaPerson = createBaseKafkaPerson('1122334455666'); PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; @@ -708,7 +708,7 @@ private class KafkaPdlPersondokumentHandlerTest { * there exists a (processed) tombstone with the same ident. */ @isTest - static void insertKafkaMessageProcessed() { + static void personIsNotUpdatedWhenTombstoneExists() { KafkaPerson3 athos = createBaseKafkaPerson('1122334455666'); PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; @@ -777,7 +777,7 @@ private class KafkaPdlPersondokumentHandlerTest { * exception should create the warning from the method name. */ @isTest - static void insertKafkaMessageWarning() { + static void when_PdlSikkerhetstiltak_IsInvalid_Expect_StatusToBeWarning() { KafkaPerson3 laurel = createBaseKafkaPerson('1122334455666'); PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; @@ -841,7 +841,7 @@ private class KafkaPdlPersondokumentHandlerTest { * TODO: check what exactly this tests */ @isTest - static void insertKafkaMessageUpdateError() { + static void when_PdlSikkerhetstiltak_IsInvalid_Expect_StatusToBeWarning2() { insert new Person__c( Name = '12345678901', INT_fnr__c = '12345678901', @@ -944,7 +944,7 @@ private class KafkaPdlPersondokumentHandlerTest { } @isTest - static void insertKafkaMessageNpidPerson() { + static void identFieldsAreSetAsExpectedFromNpid() { KafkaPerson3 kafkaPerson = createBaseKafkaPerson('1122334455666'); PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); identInfo.gruppe = PDL_IdentGruppe.NPID; @@ -981,7 +981,7 @@ private class KafkaPdlPersondokumentHandlerTest { * - deprecating the dnr and adding fnr sets name = fnr */ @isTest - static void insertKafkaMessageNpidPersonFromNpidToFnr() { + static void identFieldsAreSetAsExpectedFromRespectivelyNpidDnrAndFnr() { KafkaPerson3 kafkaPerson = createBaseKafkaPerson('1122334455666'); PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); identInfo.gruppe = PDL_IdentGruppe.NPID; @@ -1092,7 +1092,7 @@ private class KafkaPdlPersondokumentHandlerTest { **************************/ @isTest - static void mapFieldValuesExcludingAddresses() { + static void fieldsExcludingAddressesAreSetCorrectly() { KafkaPerson3 kafkaPerson = createBaseKafkaPerson('1122334455666'); PDL_IdentInformasjon identInfo = new PDL_IdentInformasjon(); identInfo.gruppe = PDL_IdentGruppe.FOLKEREGISTERIDENT; @@ -1225,7 +1225,7 @@ private class KafkaPdlPersondokumentHandlerTest { * based on all their address protections. */ @isTest - static void testHighestGradeApplies() { + static void highestGradeOfAddressProtectionApplies() { PdlAdressebeskyttelse ungraded = new PdlAdressebeskyttelse(); ungraded.gradering = PDL_AdressebeskyttelseGradering.UGRADERT; PdlAdressebeskyttelse confidential = new PdlAdressebeskyttelse(); @@ -1272,7 +1272,7 @@ private class KafkaPdlPersondokumentHandlerTest { * Ensure error is thrown on unknown address protection. */ @isTest - static void testUnknownAddressProtection() { + static void when_UnknownAddressProtectionIsProvided_ThrowError() { List kafkaMessages = new List(); kafkaMessages.add( new KafkaMessage__c( @@ -1301,7 +1301,7 @@ private class KafkaPdlPersondokumentHandlerTest { * Tests that setAddress combines fields from kafka person correctly. */ @IsTest - static void setBostedVegadresse() { + static void addressFieldsAreSetCorrectlyFromBostedVegadresse() { Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); KafkaPerson3 kafkaPerson = createBaseKafkaPerson('1122334455666'); PdlBostedsadresse bo = new PdlBostedsadresse(); @@ -1347,7 +1347,7 @@ private class KafkaPdlPersondokumentHandlerTest { * Tests that the historical address is not saved but the non-historical one is */ @IsTest - static void setNonHistoricalBosted() { + static void historicalAddressIsNotSavedButNonHistoricalIs() { Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); KafkaPerson3 kafkaPerson = createBaseKafkaPerson('1122334455666'); PdlBostedsadresse bo = new PdlBostedsadresse(); @@ -1403,7 +1403,7 @@ private class KafkaPdlPersondokumentHandlerTest { * Test secondary address, and that setAddress is actually called. */ @IsTest - static void setBostedCadastralAddress() { + static void addressFieldsAreSetCorrectlyFromCadastralAddress() { List kafkaMessages = new List(); kafkaMessages.add( new KafkaMessage__c( @@ -1428,7 +1428,7 @@ private class KafkaPdlPersondokumentHandlerTest { * Tests that address protection actually works */ @IsTest - static void dontSetProtectedAddress() { + static void when_AddressProtectionIsActive_DoNotSetAddress() { List kafkaMessages = new List(); kafkaMessages.add( new KafkaMessage__c( @@ -1451,7 +1451,7 @@ private class KafkaPdlPersondokumentHandlerTest { * Tests temporary address */ @IsTest - static void setOppholdVegadresse() { + static void addressFieldsAreSetCorrectlyFromTemporaryAddress() { Person__c person = new Person__c(INT_Confidential__c = 'UGRADERT'); KafkaPerson3 kafkaPerson = createBaseKafkaPerson('11223344556'); PdlOppholdsadresse opphold = new PdlOppholdsadresse(); @@ -1486,7 +1486,7 @@ private class KafkaPdlPersondokumentHandlerTest { * values sent in the last message. */ @IsTest - static void testDuplicateKeys() { + static void when_TwoMessagesAreSentWithDuplicateKeys_OnlyLastMessageIsUsed() { KafkaPerson3 jekyll = createBaseKafkaPerson('3138428376721', '25937424601'); jekyll.hentPerson.navn[0].fornavn = 'HENRY'; jekyll.hentPerson.navn[0].etternavn = 'JEKYLL'; @@ -1512,7 +1512,7 @@ private class KafkaPdlPersondokumentHandlerTest { * are more or less than one of them. */ @IsTest - static void testNoneOrMultipleInterpreterLanguages() { + static void interpreterLanguagesStringReturnsCorrectlyMergedLanguages() { PdlTilrettelagtkommunikasjon[] polyComms = new List(); PdlTilrettelagtkommunikasjon[] noComms = new List(); PdlTilrettelagtkommunikasjon comm1 = new PdlTilrettelagtkommunikasjon();