Skip to content

Commit

Permalink
MOSIP-31938 code changes
Browse files Browse the repository at this point in the history
Signed-off-by: Sowmya Ujjappa Banakar <[email protected]>
  • Loading branch information
Sowmya Ujjappa Banakar committed Mar 15, 2024
1 parent fd11532 commit 629afc5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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<String, String> fieldMap = new HashMap<String, String>();
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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,19 +17,13 @@
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;
import java.util.LinkedHashMap;
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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1544,11 +1548,13 @@ public void testLinkSuccessForLostUin() throws Exception {

@Test
public void testLinkSuccessForLostUinAndUpdateContactInfo() throws Exception {
ReflectionTestUtils.setField(uinGeneratorStage, "updateInfo", "phone,email,addressLine1");
Map<String, String> fieldMap = new HashMap<>();
fieldMap.put("UIN", "123456");
fieldMap.put("name", "mono");
fieldMap.put("email", "[email protected]");

fieldMap.put("addressLine1",
"[{\"language\":\"eng\",\"value\":\"abc\"},{\"language\":\"ara\",\"value\":\"abc\"}]");
List<String> defaultFields = new ArrayList<>();
defaultFields.add("name");
defaultFields.add("dob");
Expand Down Expand Up @@ -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("[email protected]")
.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)))
Expand Down

0 comments on commit 629afc5

Please sign in to comment.