From df1a4e38b89424a55a982a6a7273fce5395f7823 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Wed, 17 Jan 2024 12:15:45 +0530 Subject: [PATCH 1/2] [Mosip-30241] triming the demographic data based on the property Signed-off-by: khuddus shariff --- .../storage/mapper/PacketInfoMapper.java | 15 +++++++---- .../service/impl/PacketInfoManagerImpl.java | 7 +++-- .../storage/PacketInfoManagerImplTest.java | 27 ++++++++++++++----- 3 files changed, 36 insertions(+), 13 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 ec4dead9cb5..2118643dd1f 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 @@ -71,12 +71,17 @@ private PacketInfoMapper() { * 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(); + if(istrim) + { + value = jsonNode[i].getValue().trim(); + }else { + value = jsonNode[i].getValue(); + } } } } @@ -114,7 +119,7 @@ private static String[] getLanguages(JsonValue[] jsonNode, StringBuilder languag * @return the list */ public static List converDemographicDedupeDtoToEntity( - IndividualDemographicDedupe demoDto, String regId,String process, int iteration, String workflowInstanceId) throws NoSuchAlgorithmException { + IndividualDemographicDedupe demoDto, String regId,String process, int iteration, String workflowInstanceId,Boolean istrim) throws NoSuchAlgorithmException { regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), regId, "PacketInfoMapper::converDemographicDedupeDtoToEntity()::entry"); IndividualDemographicDedupeEntity entity; @@ -144,7 +149,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()) @@ -163,7 +168,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 4ea28232ac8..0d434dec81c 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 @@ -141,6 +141,9 @@ public class PacketInfoManagerImpl implements PacketInfoManager applicantDemographicEntities = PacketInfoMapper - .converDemographicDedupeDtoToEntity(demographicData, regId,process,iteration, workflowInstanceId); + .converDemographicDedupeDtoToEntity(demographicData, regId,process,iteration, workflowInstanceId,trimWhitespace); for (IndividualDemographicDedupeEntity applicantDemographicEntity : applicantDemographicEntities) { demographicDedupeRepository.save(applicantDemographicEntity); @@ -339,7 +342,7 @@ public void saveIndividualDemographicDedupeUpdatePacket(IndividualDemographicDed try { List applicantDemographicEntities = PacketInfoMapper - .converDemographicDedupeDtoToEntity(demographicData, registrationId,process,iteration, workflowInstanceId); + .converDemographicDedupeDtoToEntity(demographicData, registrationId,process,iteration, workflowInstanceId,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 d6c53205c4a..13d184b70ee 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 @@ -27,10 +27,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.*; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -93,6 +90,7 @@ import io.mosip.registration.processor.packet.storage.utils.PriorityBasedPacketManagerService; 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. @@ -1057,7 +1055,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(Mockito.any(), Mockito.any(),Mockito.any(),Mockito.anyInt(), any())) + Mockito.when(PacketInfoMapper.converDemographicDedupeDtoToEntity(Mockito.any(), Mockito.any(),Mockito.any(),Mockito.anyInt(), any(),any())) .thenReturn(applicantDemographicEntities); Mockito.when(demographicDedupeRepository.save(any())).thenReturn(entity); packetInfoManagerImpl.saveIndividualDemographicDedupeUpdatePacket(demographicData, @@ -1075,7 +1073,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(Mockito.any(), Mockito.any(),Mockito.any(),Mockito.anyInt(), any())) + Mockito.when(PacketInfoMapper.converDemographicDedupeDtoToEntity(Mockito.any(), Mockito.any(),Mockito.any(),Mockito.anyInt(), any(),any())) .thenReturn(applicantDemographicEntities); Mockito.when(demographicDedupeRepository.save(any())).thenThrow(exp); packetInfoManagerImpl.saveIndividualDemographicDedupeUpdatePacket(demographicData, @@ -1153,4 +1151,21 @@ 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(Mockito.any(), Mockito.any(),Mockito.any(),Mockito.anyInt(), any(),any())) + .thenReturn(applicantDemographicEntities); + Mockito.when(demographicDedupeRepository.save(any())).thenReturn(entity); + ArgumentCaptor arg2 = ArgumentCaptor.forClass(Integer.class); + packetInfoManagerImpl.saveIndividualDemographicDedupeUpdatePacket(demographicData, + "1001", "","NEW", "",1, ""); + } } From 13ff6d9c1c89e3e42e295b2c507bb9a4e8665792 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Wed, 17 Jan 2024 12:29:35 +0530 Subject: [PATCH 2/2] [Mosip-30241] triming the demographic data based on the property Signed-off-by: khuddus shariff --- .../processor/packet/storage/mapper/PacketInfoMapper.java | 5 +++++ 1 file changed, 5 insertions(+) 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 2118643dd1f..3f8313742fa 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 @@ -118,6 +118,11 @@ private static String[] getLanguages(JsonValue[] jsonNode, StringBuilder languag * @param iteration * @return the list */ + public static List converDemographicDedupeDtoToEntity( + IndividualDemographicDedupe demoDto, String regId,String process, int iteration, String workflowInstanceId) throws NoSuchAlgorithmException { + + return converDemographicDedupeDtoToEntity(demoDto,regId,process,iteration,workflowInstanceId,false); + } public static List converDemographicDedupeDtoToEntity( IndividualDemographicDedupe demoDto, String regId,String process, int iteration, String workflowInstanceId,Boolean istrim) throws NoSuchAlgorithmException { regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), regId,