From 7b8a79f956c6c7058210b1f49be755fe8a109e0f Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Fri, 22 Dec 2023 20:05:16 +0530 Subject: [PATCH 1/6] [Mosip-29862]Update UIN flow with blank value in non mandatory field value not getting updated to blank in IDRepo Signed-off-by: khuddus shariff --- .../uingenerator/stage/UinGeneratorStage.java | 6 ++ .../uigenerator/UinGeneratorStageTest.java | 66 ++++++++++++++++++- .../storage/mapper/PacketInfoMapper.java | 15 +++-- .../service/impl/PacketInfoManagerImpl.java | 7 +- .../storage/PacketInfoManagerImplTest.java | 5 +- 5 files changed, 88 insertions(+), 11 deletions(-) diff --git a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java index e35a66c5354..4dcb76ee57c 100644 --- a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java +++ b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/main/java/io/mosip/registration/processor/stages/uingenerator/stage/UinGeneratorStage.java @@ -164,6 +164,9 @@ public class UinGeneratorStage extends MosipVerticleAPIManager { @Value("${mosip.regproc.uin.generator.idrepo-max-retry-count}") Integer maxRetrycount; + @Value("${mosip.regproc.uin.generator.trim-whitespaces.simpleType-value:false}") + private boolean trimWhitespaces; + /** The core audit request builder. */ @Autowired private AuditLogRequestBuilder auditLogRequestBuilder; @@ -471,6 +474,9 @@ else if (json instanceof JSONArray) { for (int i = 0; i < jsonArray.length(); i++) { Object obj = jsonArray.get(i); HashMap hashMap = new ObjectMapper().readValue(obj.toString(), HashMap.class); + if(trimWhitespaces && hashMap.get("value") instanceof String) { + hashMap.put("value",((String)hashMap.get("value")).trim()); + } jsonList.add(hashMap); } demographicIdentity.putIfAbsent(e.getKey(), jsonList); diff --git a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java index b8a655d8ec9..706d082b6cc 100644 --- a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java +++ b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java @@ -26,6 +26,7 @@ import java.util.Map; import io.mosip.registration.processor.core.status.util.StatusUtil; +import io.mosip.registration.processor.stages.uingenerator.idrepo.dto.IdRequestDto; import org.apache.commons.io.IOUtils; import org.assertj.core.util.Lists; import org.json.JSONException; @@ -2664,4 +2665,67 @@ public void testUinGenerationSuccessWithoutUINwithErrorAsEmpty() throws Exceptio MessageDTO result = uinGeneratorStage.process(messageDTO); assertFalse(result.getInternalError()); } -} \ No newline at end of file + + @Test + public void testUinGenerationSuccessWithEmptyName() throws Exception { + ReflectionTestUtils.setField(uinGeneratorStage,"trimWhitespaces",true); + MessageDTO messageDTO = new MessageDTO(); + messageDTO.setRid("27847657360002520181210094052"); + String str = "{\"id\":\"mosip.id.read\",\"version\":\"1.0\",\"responsetime\":\"2019-04-05\",\"metadata\":null,\"response\":{\"uin\":\"2812936908\"},\"errors\":[{\"errorCode\":null,\"errorMessage\":null}]}"; + String response = "{\"uin\":\"6517036426\",\"status\":\"ASSIGNED\"}"; + + when(registrationProcessorRestClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(str); + when(registrationProcessorRestClientService.putApi(any(), any(), any(), any(), any(), any(), any())) + .thenReturn(response); + messageDTO.setReg_type(RegistrationType.NEW); + + IdResponseDTO idResponseDTO = new IdResponseDTO(); + ResponseDTO responseDTO = new ResponseDTO(); + responseDTO.setEntity("https://dev.mosip.io/idrepo/v1.0/identity/203560486746"); + responseDTO.setStatus("ACTIVATED"); + idResponseDTO.setErrors(null); + idResponseDTO.setId("mosip.id.create"); + idResponseDTO.setResponse(responseDTO); + idResponseDTO.setResponsetime("2019-01-17T06:29:01.940Z"); + idResponseDTO.setVersion("1.0"); + + ResponseWrapper responseVid = new ResponseWrapper(); + List errors = new ArrayList<>(); + responseVid.setErrors(errors); + responseVid.setVersion("v1"); + responseVid.setMetadata(null); + DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + LocalDateTime localdatetime = LocalDateTime + .parse(DateUtils.getUTCCurrentDateTimeString("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"), format); + responseVid.setResponsetime(localdatetime); + VidResponseDto vidResponseDto = new VidResponseDto(); + vidResponseDto.setVID("123456"); + vidResponseDto.setVidStatus("ACTIVE"); + responseVid.setResponse(vidResponseDto); + + when(registrationProcessorRestClientService.postApi(any(), any(), any(), any(), any(Class.class))) + .thenReturn(idResponseDTO).thenReturn(responseVid).thenReturn(response); + + Map fieldMap = new HashMap<>(); + fieldMap.put("firstName","[ {\n" + + " \"language\" : \"eng\",\n" + + " \"value\" : \" \"\n" + + "} ]"); + fieldMap.put("email", "mono@mono.com"); + fieldMap.put("phone", "23456"); + fieldMap.put("dob", "11/11/2011"); + + List defaultFields = new ArrayList<>(); + defaultFields.add("name"); + defaultFields.add("dob"); + defaultFields.add("gender"); + + when(packetManagerService.getFields(any(),any(),any(),any())).thenReturn(fieldMap); + when(idSchemaUtil.getDefaultFields(anyDouble())).thenReturn(defaultFields); + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(IdRequestDto.class); + MessageDTO result = uinGeneratorStage.process(messageDTO); + verify(registrationProcessorRestClientService, atLeastOnce()).postApi(any(), any(), any(),any(), any()); + assertFalse(result.getInternalError()); + assertTrue(result.getIsValid()); + } +} diff --git a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/mapper/PacketInfoMapper.java b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/mapper/PacketInfoMapper.java index 11feaa842d6..5d33e124cd4 100644 --- a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/mapper/PacketInfoMapper.java +++ b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/mapper/PacketInfoMapper.java @@ -99,12 +99,17 @@ public static RegAbisRefEntity convertRegAbisRefToEntity(RegAbisRefDto regAbisRe * the language * @return the json values */ - private static String getJsonValues(JsonValue[] jsonNode, String language) { + private static String getJsonValues(JsonValue[] jsonNode, String language,boolean istrim) { String value = null; if (jsonNode != null) { for (int i = 0; i < jsonNode.length; i++) { if (jsonNode[i].getLanguage().equals(language)) { - value = jsonNode[i].getValue().trim(); + if(istrim) + { + value = jsonNode[i].getValue().trim(); + }else { + value = jsonNode[i].getValue(); + } } } } @@ -141,7 +146,7 @@ private static String[] getLanguages(JsonValue[] jsonNode, StringBuilder languag * @return the list */ public static List converDemographicDedupeDtoToEntity( - IndividualDemographicDedupe demoDto, String regId) throws NoSuchAlgorithmException { + IndividualDemographicDedupe demoDto, String regId,Boolean istrim) throws NoSuchAlgorithmException { regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), regId, "PacketInfoMapper::converDemographicDedupeDtoToEntity()::entry"); IndividualDemographicDedupeEntity entity; @@ -168,7 +173,7 @@ public static List converDemographicDedupeDto if (demoDto.getName()!=null &&!demoDto.getName().isEmpty()) { for (JsonValue[] jsonValue : demoDto.getName()) { - applicantFullName.append(getJsonValues(jsonValue, languageArray[i])); + applicantFullName.append(getJsonValues(jsonValue, languageArray[i],istrim)); } entity.setName(!applicantFullName.toString().isEmpty() ? getHMACHashCode(applicantFullName.toString().trim().toUpperCase()) @@ -187,7 +192,7 @@ public static List converDemographicDedupeDto throw new DateParseException(PlatformErrorMessages.RPR_SYS_PARSING_DATE_EXCEPTION.getMessage(), e); } } - entity.setGender(getHMACHashCode(getJsonValues(demoDto.getGender(), languageArray[i]))); + entity.setGender(getHMACHashCode(getJsonValues(demoDto.getGender(), languageArray[i],istrim))); entity.setPhone(getHMACHashCode(demoDto.getPhone())); entity.setEmail(getHMACHashCode(demoDto.getEmail())); demogrphicDedupeEntities.add(entity); diff --git a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/service/impl/PacketInfoManagerImpl.java b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/service/impl/PacketInfoManagerImpl.java index 3b997efd9d9..80077820ef8 100644 --- a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/service/impl/PacketInfoManagerImpl.java +++ b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/service/impl/PacketInfoManagerImpl.java @@ -145,6 +145,9 @@ public class PacketInfoManagerImpl implements PacketInfoManager applicantDemographicEntities = PacketInfoMapper - .converDemographicDedupeDtoToEntity(demographicData, regId); + .converDemographicDedupeDtoToEntity(demographicData, regId,trimWhitespace); for (IndividualDemographicDedupeEntity applicantDemographicEntity : applicantDemographicEntities) { demographicDedupeRepository.save(applicantDemographicEntity); @@ -343,7 +346,7 @@ public void saveIndividualDemographicDedupeUpdatePacket(IndividualDemographicDed try { List applicantDemographicEntities = PacketInfoMapper - .converDemographicDedupeDtoToEntity(demographicData, registrationId); + .converDemographicDedupeDtoToEntity(demographicData, registrationId,trimWhitespace); for (IndividualDemographicDedupeEntity applicantDemographicEntity : applicantDemographicEntities) { demographicDedupeRepository.save(applicantDemographicEntity); diff --git a/registration-processor/registration-processor-info-storage-service/src/test/java/io/mosip/registration/processor/packet/storage/PacketInfoManagerImplTest.java b/registration-processor/registration-processor-info-storage-service/src/test/java/io/mosip/registration/processor/packet/storage/PacketInfoManagerImplTest.java index 5f0293f809d..f4a7c53485a 100644 --- a/registration-processor/registration-processor-info-storage-service/src/test/java/io/mosip/registration/processor/packet/storage/PacketInfoManagerImplTest.java +++ b/registration-processor/registration-processor-info-storage-service/src/test/java/io/mosip/registration/processor/packet/storage/PacketInfoManagerImplTest.java @@ -1011,7 +1011,7 @@ public void testsaveIndividualDemographicDedupe() throws NoSuchAlgorithmExceptio entity.setDob("2019-03-02T06:29:41.011Z"); applicantDemographicEntities.add(entity); PowerMockito.mockStatic(PacketInfoMapper.class); - Mockito.when(PacketInfoMapper.converDemographicDedupeDtoToEntity(any(), any())) + Mockito.when(PacketInfoMapper.converDemographicDedupeDtoToEntity(any(),any(),any())) .thenReturn(applicantDemographicEntities); Mockito.when(demographicDedupeRepository.save(any())).thenReturn(entity); packetInfoManagerImpl.saveIndividualDemographicDedupeUpdatePacket(demographicData, "1001", "", ""); @@ -1028,11 +1028,10 @@ public void testsaveIndividualDemographicDedupeException() throws NoSuchAlgorith entity.setDob("2019-03-02T06:29:41.011Z"); applicantDemographicEntities.add(entity); PowerMockito.mockStatic(PacketInfoMapper.class); - Mockito.when(PacketInfoMapper.converDemographicDedupeDtoToEntity(any(), any())) + Mockito.when(PacketInfoMapper.converDemographicDedupeDtoToEntity(any(), any(),any())) .thenReturn(applicantDemographicEntities); Mockito.when(demographicDedupeRepository.save(any())).thenThrow(exp); packetInfoManagerImpl.saveIndividualDemographicDedupeUpdatePacket(demographicData, "1001", "", ""); - } @Test From 7018c652cbc9890e930537a23f7c9328de9ebbc6 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Fri, 22 Dec 2023 20:09:04 +0530 Subject: [PATCH 2/6] [Mosip-29862]Update UIN flow with blank value in non mandatory field value not getting updated to blank in IDRepo Signed-off-by: khuddus shariff --- .../processor/stages/uigenerator/UinGeneratorStageTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java index 706d082b6cc..caef5bb2d49 100644 --- a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java +++ b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java @@ -26,7 +26,6 @@ import java.util.Map; import io.mosip.registration.processor.core.status.util.StatusUtil; -import io.mosip.registration.processor.stages.uingenerator.idrepo.dto.IdRequestDto; import org.apache.commons.io.IOUtils; import org.assertj.core.util.Lists; import org.json.JSONException; @@ -2722,7 +2721,6 @@ public void testUinGenerationSuccessWithEmptyName() throws Exception { when(packetManagerService.getFields(any(),any(),any(),any())).thenReturn(fieldMap); when(idSchemaUtil.getDefaultFields(anyDouble())).thenReturn(defaultFields); - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(IdRequestDto.class); MessageDTO result = uinGeneratorStage.process(messageDTO); verify(registrationProcessorRestClientService, atLeastOnce()).postApi(any(), any(), any(),any(), any()); assertFalse(result.getInternalError()); From f85362e14e021c8310447ea94ea3ca1a2aa6a107 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Wed, 27 Dec 2023 12:07:26 +0530 Subject: [PATCH 3/6] Packet stuck at validate packet stage in qa-trinity after doing update uin in resident service. Signed-off-by: khuddus shariff --- .../uigenerator/UinGeneratorStageTest.java | 60 +++++++++------- .../storage/mapper/PacketInfoMapper.java | 72 ++++++++++++++++++- .../service/impl/PacketInfoManagerImpl.java | 3 +- 3 files changed, 106 insertions(+), 29 deletions(-) diff --git a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java index caef5bb2d49..3a88b5a3f24 100644 --- a/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java +++ b/registration-processor/core-processor/registration-processor-uin-generator-stage/src/test/java/io/mosip/registration/processor/stages/uigenerator/UinGeneratorStageTest.java @@ -1,19 +1,13 @@ package io.mosip.registration.processor.stages.uigenerator; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyDouble; import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.*; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.lang.reflect.Field; import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; @@ -25,9 +19,14 @@ import java.util.List; import java.util.Map; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.google.gson.JsonObject; import io.mosip.registration.processor.core.status.util.StatusUtil; +import io.mosip.registration.processor.stages.uingenerator.idrepo.dto.IdRequestDto; import org.apache.commons.io.IOUtils; import org.assertj.core.util.Lists; +import org.json.JSONArray; import org.json.JSONException; import org.json.simple.JSONObject; import org.junit.Before; @@ -407,7 +406,7 @@ public void testUinGenerationResponseNull() throws Exception { IdResponseDTO idResponseDTO = new IdResponseDTO(); ResponseDTO responseDTO = new ResponseDTO(); - + ResponseWrapper responseVid = new ResponseWrapper(); List errors = new ArrayList<>(); responseVid.setErrors(errors); @@ -524,7 +523,7 @@ public void testUinGenerationSuccessWithoutUINAndUinUnused() throws Exception { assertFalse(result.getInternalError()); } - + @Test public void testUinReActivationifAlreadyActivatedSuccess() throws Exception { @@ -576,7 +575,7 @@ public void testUinReActivationifAlreadyActivatedSuccess() throws Exception { assertFalse(result.getIsValid()); } - + @Test public void testUinReActivationResponseStatusAsActivated() throws Exception { Map fieldMap = new HashMap<>(); @@ -765,7 +764,7 @@ public void testUinReActivationWithStatusAsAny() throws Exception { } - + @Test public void testUinReActivationIfNotActivatedSuccess() throws Exception { @@ -1077,7 +1076,7 @@ public void deactivateTestSuccess() throws ApisResourceAccessException, IOExcept MessageDTO result = uinGeneratorStage.process(messageDTO); assertTrue(result.getIsValid()); } - + @Test public void checkIsUinDeactivatedSuccess() throws ApisResourceAccessException, IOException, JSONException, JsonProcessingException, PacketManagerException { @@ -1170,7 +1169,7 @@ public void deactivateTestWithDeactivate() throws ApisResourceAccessException, I MessageDTO result = uinGeneratorStage.process(messageDTO); //assertTrue(result.getIsValid()); } - + @Test public void deactivateTestWithNullResponseDTO() throws ApisResourceAccessException, PacketManagerException, IOException, JsonProcessingException, JSONException { Map fieldMap = new HashMap<>(); @@ -1217,7 +1216,7 @@ public void deactivateTestWithNullResponseDTO() throws ApisResourceAccessExcepti MessageDTO result = uinGeneratorStage.process(messageDTO); //assertTrue(result.getIsValid()); } - + @Test public void deactivateTestForExistingUinTestSuccess() throws ApisResourceAccessException, PacketManagerException, IOException, JsonProcessingException, JSONException { @@ -1351,8 +1350,8 @@ public void apisResourceAccessExceptionTest() throws ApisResourceAccessException .thenThrow(apisResourceAccessException); uinGeneratorStage.process(messageDTO); } - - + + @Test public void testHttpServerErrorException() throws Exception { @@ -1372,7 +1371,7 @@ public void testHttpServerErrorException() throws Exception { when(registrationProcessorRestClientService.getApi(any(), any(), anyString(), any(), any())) .thenThrow(apisResourceAccessException); - + MessageDTO result = uinGeneratorStage.process(messageDTO); //assertTrue(result.getIsValid()); @@ -1394,7 +1393,7 @@ public void testHttpClientErrorException() throws Exception { when(registrationProcessorRestClientService.getApi(any(), any(), anyString(), any(), any())) .thenThrow(apisResourceAccessException); - + MessageDTO result = uinGeneratorStage.process(messageDTO); //assertTrue(result.getIsValid()); @@ -1413,7 +1412,7 @@ public void testUinGenerationHttpClientErrorException() throws Exception { when(apisResourceAccessException.getCause()).thenReturn(httpClientErrorException); when(registrationProcessorRestClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(str); - + when(registrationProcessorRestClientService.postApi(any(), any(), any(), any(), any())).thenThrow(apisResourceAccessException); messageDTO.setReg_type(RegistrationType.NEW); @@ -1435,7 +1434,7 @@ public void testUinGenerationHttpServerErrorException() throws Exception { when(apisResourceAccessException.getCause()).thenReturn(httpServerErrorException); when(registrationProcessorRestClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(str); - + when(registrationProcessorRestClientService.postApi(any(), any(), any(), any(), any())).thenThrow(apisResourceAccessException); messageDTO.setReg_type(RegistrationType.NEW); @@ -1488,7 +1487,7 @@ public void getApiExceptionTest() throws ApisResourceAccessException { .thenThrow(apisResourceAccessException); uinGeneratorStage.process(messageDTO); } - + @Test public void testIOException() { IOException exception = new IOException("File not found"); @@ -1924,7 +1923,7 @@ public void testUpdateSuccess() throws Exception { assertFalse(result.getInternalError()); } - + @Test public void testUpdateWithoutIdResponseDto() throws Exception { Map fieldMap = new HashMap<>(); @@ -1954,7 +1953,7 @@ public void testUpdateWithoutIdResponseDto() throws Exception { .thenReturn(responsedto); IdResponseDTO idResponseDTO1 = new IdResponseDTO(); - + when(registrationProcessorRestClientService.patchApi(any(), any(), any(), any(), any(), any())) .thenReturn(idResponseDTO1); @@ -2013,7 +2012,7 @@ public void testUpdateunsuccess() throws Exception { assertFalse(result.getIsValid()); } - @Ignore + @Ignore @Test public void testUinAlreadyExists() throws Exception { Map fieldMap = new HashMap<>(); @@ -2168,7 +2167,7 @@ public void testJsonProcessingException() throws ApisResourceAccessException, IO MessageDTO result = uinGeneratorStage.process(messageDTO); assertTrue(result.getInternalError()); } - + @Test public void testIdRecordExistTrueFlagWithErrorResponse() throws Exception { @@ -2721,8 +2720,15 @@ public void testUinGenerationSuccessWithEmptyName() throws Exception { when(packetManagerService.getFields(any(),any(),any(),any())).thenReturn(fieldMap); when(idSchemaUtil.getDefaultFields(anyDouble())).thenReturn(defaultFields); + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(IdRequestDto.class); + MessageDTO result = uinGeneratorStage.process(messageDTO); - verify(registrationProcessorRestClientService, atLeastOnce()).postApi(any(), any(), any(),any(), any()); + verify(registrationProcessorRestClientService,Mockito.times(2)).postApi(any(), any(), any(),argumentCaptor.capture(),any()); + ObjectMapper objectMapper = new ObjectMapper(); + String jsonobject=objectMapper.writeValueAsString(argumentCaptor.getAllValues().get(0).getRequest().getIdentity()); + JsonNode jsonNode=objectMapper.readTree(jsonobject); + + assertEquals("",jsonNode.get("firstName").asText()); assertFalse(result.getInternalError()); assertTrue(result.getIsValid()); } diff --git a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/mapper/PacketInfoMapper.java b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/mapper/PacketInfoMapper.java index 5d33e124cd4..a2845fc5e87 100644 --- a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/mapper/PacketInfoMapper.java +++ b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/mapper/PacketInfoMapper.java @@ -99,6 +99,18 @@ public static RegAbisRefEntity convertRegAbisRefToEntity(RegAbisRefDto regAbisRe * the language * @return the json values */ + + private static String getJsonValues(JsonValue[] jsonNode, String language) { + String value = null; + if (jsonNode != null) { + for (int i = 0; i < jsonNode.length; i++) { + if (jsonNode[i].getLanguage().equals(language)) { + value = jsonNode[i].getValue(); + } + } + } + return value; + } private static String getJsonValues(JsonValue[] jsonNode, String language,boolean istrim) { String value = null; if (jsonNode != null) { @@ -113,7 +125,6 @@ private static String getJsonValues(JsonValue[] jsonNode, String language,boolea } } } - return value; } @@ -145,6 +156,65 @@ private static String[] getLanguages(JsonValue[] jsonNode, StringBuilder languag * the reg id * @return the list */ + + public static List converDemographicDedupeDtoToEntity( + IndividualDemographicDedupe demoDto, String regId) throws NoSuchAlgorithmException { + regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), regId, + "PacketInfoMapper::converDemographicDedupeDtoToEntity()::entry"); + IndividualDemographicDedupeEntity entity; + IndividualDemographicDedupePKEntity applicantDemographicPKEntity; + List demogrphicDedupeEntities = new ArrayList<>(); + StringBuilder languages = new StringBuilder(); + if (demoDto.getName()!=null && !demoDto.getName().isEmpty()) { + for (JsonValue[] jsonValue : demoDto.getName()) + getLanguages(jsonValue, languages); + } + String[] languageArray = getLanguages(demoDto.getGender(), languages); + for (int i = 0; i < languageArray.length; i++) { + entity = new IndividualDemographicDedupeEntity(); + applicantDemographicPKEntity = new IndividualDemographicDedupePKEntity(); + + applicantDemographicPKEntity.setRegId(regId); + applicantDemographicPKEntity.setLangCode(languageArray[i]); + entity.setCrDtimes(LocalDateTime.now(ZoneId.of("UTC"))); + entity.setUpdDtimes(LocalDateTime.now(ZoneId.of("UTC"))); + entity.setId(applicantDemographicPKEntity); + entity.setIsActive(true); + entity.setIsDeleted(false); + StringBuilder applicantFullName = new StringBuilder(); + + if (demoDto.getName()!=null &&!demoDto.getName().isEmpty()) { + for (JsonValue[] jsonValue : demoDto.getName()) { + applicantFullName.append(getJsonValues(jsonValue, languageArray[i])); + } + entity.setName(!applicantFullName.toString().isEmpty() + ? getHMACHashCode(applicantFullName.toString().trim().toUpperCase()) + : null); + } + + if (demoDto.getDateOfBirth() != null) { + try { + Date date = new SimpleDateFormat("yyyy/MM/dd").parse(demoDto.getDateOfBirth()); + + entity.setDob(getHMACHashCode(demoDto.getDateOfBirth())); + } catch (ParseException e) { + regProcLogger.error(LoggerFileConstant.SESSIONID.toString(), + LoggerFileConstant.REGISTRATIONID.toString(), regId, + e.getMessage() + ExceptionUtils.getStackTrace(e)); + throw new DateParseException(PlatformErrorMessages.RPR_SYS_PARSING_DATE_EXCEPTION.getMessage(), e); + } + } + entity.setGender(getHMACHashCode(getJsonValues(demoDto.getGender(), languageArray[i]))); + entity.setPhone(getHMACHashCode(demoDto.getPhone())); + entity.setEmail(getHMACHashCode(demoDto.getEmail())); + demogrphicDedupeEntities.add(entity); + + } + + regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), regId, + "PacketInfoMapper::converDemographicDedupeDtoToEntity()::exit"); + return demogrphicDedupeEntities; + } public static List converDemographicDedupeDtoToEntity( IndividualDemographicDedupe demoDto, String regId,Boolean istrim) throws NoSuchAlgorithmException { regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), regId, diff --git a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/service/impl/PacketInfoManagerImpl.java b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/service/impl/PacketInfoManagerImpl.java index 80077820ef8..3ba5c04cb2f 100644 --- a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/service/impl/PacketInfoManagerImpl.java +++ b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/service/impl/PacketInfoManagerImpl.java @@ -346,7 +346,8 @@ public void saveIndividualDemographicDedupeUpdatePacket(IndividualDemographicDed try { List applicantDemographicEntities = PacketInfoMapper - .converDemographicDedupeDtoToEntity(demographicData, registrationId,trimWhitespace); + .converDemographicDedupeDtoToEntity(demographicData, registrationId, trimWhitespace); + for (IndividualDemographicDedupeEntity applicantDemographicEntity : applicantDemographicEntities) { demographicDedupeRepository.save(applicantDemographicEntity); From 1ffb14f56649383026c14bf803d9c84501e437b1 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Wed, 27 Dec 2023 12:20:55 +0530 Subject: [PATCH 4/6] Packet stuck at validate packet stage in qa-trinity after doing update uin in resident service. Signed-off-by: khuddus shariff --- .../storage/PacketInfoManagerImplTest.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/registration-processor/registration-processor-info-storage-service/src/test/java/io/mosip/registration/processor/packet/storage/PacketInfoManagerImplTest.java b/registration-processor/registration-processor-info-storage-service/src/test/java/io/mosip/registration/processor/packet/storage/PacketInfoManagerImplTest.java index f4a7c53485a..442b6cde5f8 100644 --- a/registration-processor/registration-processor-info-storage-service/src/test/java/io/mosip/registration/processor/packet/storage/PacketInfoManagerImplTest.java +++ b/registration-processor/registration-processor-info-storage-service/src/test/java/io/mosip/registration/processor/packet/storage/PacketInfoManagerImplTest.java @@ -85,6 +85,7 @@ import io.mosip.registration.processor.packet.storage.service.impl.PacketInfoManagerImpl; import io.mosip.registration.processor.packet.storage.utils.Utilities; import io.mosip.registration.processor.rest.client.audit.builder.AuditLogRequestBuilder; +import org.springframework.test.util.ReflectionTestUtils; /** * The Class PacketInfoManagerImplTest. @@ -1011,7 +1012,7 @@ public void testsaveIndividualDemographicDedupe() throws NoSuchAlgorithmExceptio entity.setDob("2019-03-02T06:29:41.011Z"); applicantDemographicEntities.add(entity); PowerMockito.mockStatic(PacketInfoMapper.class); - Mockito.when(PacketInfoMapper.converDemographicDedupeDtoToEntity(any(),any(),any())) + Mockito.when(PacketInfoMapper.converDemographicDedupeDtoToEntity(any(),any())) .thenReturn(applicantDemographicEntities); Mockito.when(demographicDedupeRepository.save(any())).thenReturn(entity); packetInfoManagerImpl.saveIndividualDemographicDedupeUpdatePacket(demographicData, "1001", "", ""); @@ -1028,7 +1029,7 @@ public void testsaveIndividualDemographicDedupeException() throws NoSuchAlgorith entity.setDob("2019-03-02T06:29:41.011Z"); applicantDemographicEntities.add(entity); PowerMockito.mockStatic(PacketInfoMapper.class); - Mockito.when(PacketInfoMapper.converDemographicDedupeDtoToEntity(any(), any(),any())) + Mockito.when(PacketInfoMapper.converDemographicDedupeDtoToEntity(any(), any())) .thenReturn(applicantDemographicEntities); Mockito.when(demographicDedupeRepository.save(any())).thenThrow(exp); packetInfoManagerImpl.saveIndividualDemographicDedupeUpdatePacket(demographicData, "1001", "", ""); @@ -1104,4 +1105,22 @@ public void dataAccessLayerExceptionTest() { } + + @Test + public void testsaveIndividualDemographicDedupeWithTrim() throws NoSuchAlgorithmException { + ReflectionTestUtils.setField(packetInfoManagerImpl,"trimWhitespace",true); + IndividualDemographicDedupe demographicData = new IndividualDemographicDedupe(); + demographicData.setDateOfBirth("2019-03-02T06:29:41.011Z"); + List applicantDemographicEntities = new ArrayList<>(); + IndividualDemographicDedupeEntity entity = new IndividualDemographicDedupeEntity(); + entity.setDob("2019-03-02T06:29:41.011Z"); + applicantDemographicEntities.add(entity); + PowerMockito.mockStatic(PacketInfoMapper.class); + Mockito.when(PacketInfoMapper.converDemographicDedupeDtoToEntity(any(),any(),any())) + .thenReturn(applicantDemographicEntities); + Mockito.when(demographicDedupeRepository.save(any())).thenReturn(entity); + packetInfoManagerImpl.saveIndividualDemographicDedupeUpdatePacket(demographicData, "1001", "", ""); + + } + } From 7cce66abb5af95ac73c140968f440267dd264213 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Thu, 28 Dec 2023 16:28:21 +0530 Subject: [PATCH 5/6] Packet stuck at validate packet stage in qa-trinity after doing update uin in resident service. Signed-off-by: khuddus shariff --- .../storage/mapper/PacketInfoMapper.java | 55 +------------------ .../storage/PacketInfoManagerImplTest.java | 2 +- 2 files changed, 2 insertions(+), 55 deletions(-) diff --git a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/mapper/PacketInfoMapper.java b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/mapper/PacketInfoMapper.java index a2845fc5e87..e7a57e43582 100644 --- a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/mapper/PacketInfoMapper.java +++ b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/mapper/PacketInfoMapper.java @@ -159,61 +159,8 @@ private static String[] getLanguages(JsonValue[] jsonNode, StringBuilder languag public static List converDemographicDedupeDtoToEntity( IndividualDemographicDedupe demoDto, String regId) throws NoSuchAlgorithmException { - regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), regId, - "PacketInfoMapper::converDemographicDedupeDtoToEntity()::entry"); - IndividualDemographicDedupeEntity entity; - IndividualDemographicDedupePKEntity applicantDemographicPKEntity; - List demogrphicDedupeEntities = new ArrayList<>(); - StringBuilder languages = new StringBuilder(); - if (demoDto.getName()!=null && !demoDto.getName().isEmpty()) { - for (JsonValue[] jsonValue : demoDto.getName()) - getLanguages(jsonValue, languages); - } - String[] languageArray = getLanguages(demoDto.getGender(), languages); - for (int i = 0; i < languageArray.length; i++) { - entity = new IndividualDemographicDedupeEntity(); - applicantDemographicPKEntity = new IndividualDemographicDedupePKEntity(); - - applicantDemographicPKEntity.setRegId(regId); - applicantDemographicPKEntity.setLangCode(languageArray[i]); - entity.setCrDtimes(LocalDateTime.now(ZoneId.of("UTC"))); - entity.setUpdDtimes(LocalDateTime.now(ZoneId.of("UTC"))); - entity.setId(applicantDemographicPKEntity); - entity.setIsActive(true); - entity.setIsDeleted(false); - StringBuilder applicantFullName = new StringBuilder(); - - if (demoDto.getName()!=null &&!demoDto.getName().isEmpty()) { - for (JsonValue[] jsonValue : demoDto.getName()) { - applicantFullName.append(getJsonValues(jsonValue, languageArray[i])); - } - entity.setName(!applicantFullName.toString().isEmpty() - ? getHMACHashCode(applicantFullName.toString().trim().toUpperCase()) - : null); - } - - if (demoDto.getDateOfBirth() != null) { - try { - Date date = new SimpleDateFormat("yyyy/MM/dd").parse(demoDto.getDateOfBirth()); - - entity.setDob(getHMACHashCode(demoDto.getDateOfBirth())); - } catch (ParseException e) { - regProcLogger.error(LoggerFileConstant.SESSIONID.toString(), - LoggerFileConstant.REGISTRATIONID.toString(), regId, - e.getMessage() + ExceptionUtils.getStackTrace(e)); - throw new DateParseException(PlatformErrorMessages.RPR_SYS_PARSING_DATE_EXCEPTION.getMessage(), e); - } - } - entity.setGender(getHMACHashCode(getJsonValues(demoDto.getGender(), languageArray[i]))); - entity.setPhone(getHMACHashCode(demoDto.getPhone())); - entity.setEmail(getHMACHashCode(demoDto.getEmail())); - demogrphicDedupeEntities.add(entity); - - } - regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), regId, - "PacketInfoMapper::converDemographicDedupeDtoToEntity()::exit"); - return demogrphicDedupeEntities; + return converDemographicDedupeDtoToEntity(demoDto,regId,false); } public static List converDemographicDedupeDtoToEntity( IndividualDemographicDedupe demoDto, String regId,Boolean istrim) throws NoSuchAlgorithmException { diff --git a/registration-processor/registration-processor-info-storage-service/src/test/java/io/mosip/registration/processor/packet/storage/PacketInfoManagerImplTest.java b/registration-processor/registration-processor-info-storage-service/src/test/java/io/mosip/registration/processor/packet/storage/PacketInfoManagerImplTest.java index 442b6cde5f8..19f8eac8499 100644 --- a/registration-processor/registration-processor-info-storage-service/src/test/java/io/mosip/registration/processor/packet/storage/PacketInfoManagerImplTest.java +++ b/registration-processor/registration-processor-info-storage-service/src/test/java/io/mosip/registration/processor/packet/storage/PacketInfoManagerImplTest.java @@ -1029,7 +1029,7 @@ public void testsaveIndividualDemographicDedupeException() throws NoSuchAlgorith entity.setDob("2019-03-02T06:29:41.011Z"); applicantDemographicEntities.add(entity); PowerMockito.mockStatic(PacketInfoMapper.class); - Mockito.when(PacketInfoMapper.converDemographicDedupeDtoToEntity(any(), any())) + Mockito.when(PacketInfoMapper.converDemographicDedupeDtoToEntity(any(),any(),any())) .thenReturn(applicantDemographicEntities); Mockito.when(demographicDedupeRepository.save(any())).thenThrow(exp); packetInfoManagerImpl.saveIndividualDemographicDedupeUpdatePacket(demographicData, "1001", "", ""); From 218c068adb495f59df9d31b28aa71cb708ae4bdf Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Sun, 31 Dec 2023 16:51:33 +0530 Subject: [PATCH 6/6] Packet stuck at validate packet stage in qa-trinity after doing update uin in resident service. Signed-off-by: khuddus shariff --- .../packet/storage/mapper/PacketInfoMapper.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/mapper/PacketInfoMapper.java b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/mapper/PacketInfoMapper.java index e7a57e43582..65149a04de6 100644 --- a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/mapper/PacketInfoMapper.java +++ b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/mapper/PacketInfoMapper.java @@ -100,17 +100,6 @@ public static RegAbisRefEntity convertRegAbisRefToEntity(RegAbisRefDto regAbisRe * @return the json values */ - private static String getJsonValues(JsonValue[] jsonNode, String language) { - String value = null; - if (jsonNode != null) { - for (int i = 0; i < jsonNode.length; i++) { - if (jsonNode[i].getLanguage().equals(language)) { - value = jsonNode[i].getValue(); - } - } - } - return value; - } private static String getJsonValues(JsonValue[] jsonNode, String language,boolean istrim) { String value = null; if (jsonNode != null) {