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 63c05ac64ac..fd94304312a 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 @@ -1011,12 +1011,13 @@ protected String getPropertyPrefix() { * @throws IOException Signals that an I/O exception has * occurred. * @throws IdrepoDraftReprocessableException + * @throws JSONException */ @SuppressWarnings("unchecked") private IdResponseDTO lostAndUpdateUin(String lostPacketRegId, String matchedRegId, String process, MessageDTO object, LogDescription description) throws ApisResourceAccessException, IOException, io.mosip.kernel.core.util.exception.JsonProcessingException, PacketManagerException, IdrepoDraftException, - IdrepoDraftReprocessableException { + IdrepoDraftReprocessableException, JSONException { IdResponseDTO idResponse = null; String uin = idRepoService.getUinByRid(matchedRegId, utility.getGetRegProcessorDemographicIdentity()); @@ -1035,15 +1036,23 @@ private IdResponseDTO lostAndUpdateUin(String lostPacketRegId, String matchedReg String schemaVersion = packetManagerService.getFieldByMappingJsonKey(lostPacketRegId, MappingJsonConstants.IDSCHEMA_VERSION, process, ProviderStageName.UIN_GENERATOR); identityObject.put(idschemaversion, convertIdschemaToDouble ? Double.valueOf(schemaVersion) : schemaVersion); regProcLogger.info("Fields to be updated "+updateInfo); - if (null != updateInfo && !updateInfo.isEmpty()) { - String[] upd = updateInfo.split(","); - for (String infoField : upd) { - String fldValue = packetManagerService.getField(lostPacketRegId, infoField, process, - ProviderStageName.UIN_GENERATOR); - if (null != fldValue) - identityObject.put(infoField, fldValue); + Map fieldMap = new HashMap(); + if (StringUtils.isNotEmpty(updateInfo)) { + String[] updateFields = updateInfo.split(","); + for (String fieldName : updateFields) { + String actualFieldName = JsonUtil.getJSONValue( + JsonUtil.getJSONObject(regProcessorIdentityJson, fieldName), + MappingJsonConstants.VALUE); + if (StringUtils.isNotEmpty(actualFieldName)) { + String fldValue = packetManagerService.getField(lostPacketRegId, actualFieldName, process, + ProviderStageName.UIN_GENERATOR); + if (null != fldValue) + fieldMap.put(actualFieldName, fldValue); + } + } } + loadDemographicIdentity(fieldMap, identityObject); requestDto.setRegistrationId(lostPacketRegId); requestDto.setIdentity(identityObject); 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 a94473058a9..0221f39f1b3 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,11 +1,14 @@ package io.mosip.registration.processor.stages.uigenerator; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; 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 static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.io.ByteArrayInputStream; import java.io.File; @@ -14,8 +17,6 @@ import java.io.InputStream; import java.lang.reflect.Field; import java.nio.charset.StandardCharsets; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -23,10 +24,6 @@ import java.util.List; import java.util.Map; -import com.fasterxml.jackson.databind.JsonNode; -import io.mosip.kernel.core.util.DateUtils; -import io.mosip.registration.processor.packet.manager.dto.IdRequestDto; -import io.mosip.registration.processor.stages.uingenerator.dto.VidResponseDto; import org.apache.commons.io.IOUtils; import org.assertj.core.util.Lists; import org.json.JSONException; @@ -35,7 +32,12 @@ import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.*; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -46,6 +48,7 @@ import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.HttpServerErrorException; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import io.mosip.kernel.biometrics.constant.BiometricType; @@ -83,6 +86,7 @@ import io.mosip.registration.processor.core.spi.restclient.RegistrationProcessorRestClientService; import io.mosip.registration.processor.core.util.JsonUtil; import io.mosip.registration.processor.core.util.RegistrationExceptionMapperUtil; +import io.mosip.registration.processor.packet.manager.dto.IdRequestDto; import io.mosip.registration.processor.packet.manager.dto.IdResponseDTO; import io.mosip.registration.processor.packet.manager.dto.ResponseDTO; import io.mosip.registration.processor.packet.manager.exception.IdrepoDraftException; @@ -1544,11 +1548,13 @@ public void testLinkSuccessForLostUin() throws Exception { @Test public void testLinkSuccessForLostUinAndUpdateContactInfo() throws Exception { + ReflectionTestUtils.setField(uinGeneratorStage, "updateInfo", "phone,email,addressLine1"); Map fieldMap = new HashMap<>(); fieldMap.put("UIN", "123456"); fieldMap.put("name", "mono"); fieldMap.put("email", "mono@mono.com"); - + fieldMap.put("addressLine1", + "[{\"language\":\"eng\",\"value\":\"abc\"},{\"language\":\"ara\",\"value\":\"abc\"}]"); List defaultFields = new ArrayList<>(); defaultFields.add("name"); defaultFields.add("dob"); @@ -1580,7 +1586,9 @@ public void testLinkSuccessForLostUinAndUpdateContactInfo() throws Exception { idResponseDTO.setResponse(responseDTO); idResponseDTO.setResponsetime("2019-01-17T06:29:01.940Z"); idResponseDTO.setVersion("1.0"); - when(packetManagerService.getField(any(), any(), any(),any())).thenReturn("989879234"); + when(packetManagerService.getField(any(), any(), any(), any())).thenReturn("989879234") + .thenReturn("mono@mono.com") + .thenReturn("[{\"language\":\"eng\",\"value\":\"abc\"},{\"language\":\"ara\",\"value\":\"abc\"}]"); when(idrepoDraftService.idrepoUpdateDraft(anyString(), any(), any())).thenReturn(idResponseDTO); when(registrationProcessorRestClientService.postApi(any(), any(), any(), any(), any(Class.class)))