Skip to content

Commit

Permalink
Merge pull request #1814 from Khuddusshariff0022/1.1.5.5_MOSIP_29862_…
Browse files Browse the repository at this point in the history
…Update_UIN_flow_with_blank_value_in_non_mandatory_field_value_not_getting_updated_to_blank_in_IDRepo

[MOSIP-29862] Update UIN flow with blank value in non mandatory field…
  • Loading branch information
vishwa-vyom authored Jan 2, 2024
2 parents 514faba + 218c068 commit 2a0a001
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -471,6 +474,9 @@ else if (json instanceof JSONArray) {
for (int i = 0; i < jsonArray.length(); i++) {
Object obj = jsonArray.get(i);
HashMap<String, Object> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -407,7 +406,7 @@ public void testUinGenerationResponseNull() throws Exception {

IdResponseDTO idResponseDTO = new IdResponseDTO();
ResponseDTO responseDTO = new ResponseDTO();

ResponseWrapper<VidResponseDto> responseVid = new ResponseWrapper<VidResponseDto>();
List<ErrorDTO> errors = new ArrayList<>();
responseVid.setErrors(errors);
Expand Down Expand Up @@ -524,7 +523,7 @@ public void testUinGenerationSuccessWithoutUINAndUinUnused() throws Exception {
assertFalse(result.getInternalError());

}

@Test
public void testUinReActivationifAlreadyActivatedSuccess() throws Exception {

Expand Down Expand Up @@ -576,7 +575,7 @@ public void testUinReActivationifAlreadyActivatedSuccess() throws Exception {
assertFalse(result.getIsValid());

}

@Test
public void testUinReActivationResponseStatusAsActivated() throws Exception {
Map<String, String> fieldMap = new HashMap<>();
Expand Down Expand Up @@ -765,7 +764,7 @@ public void testUinReActivationWithStatusAsAny() throws Exception {

}



@Test
public void testUinReActivationIfNotActivatedSuccess() throws Exception {
Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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<String, String> fieldMap = new HashMap<>();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1351,8 +1350,8 @@ public void apisResourceAccessExceptionTest() throws ApisResourceAccessException
.thenThrow(apisResourceAccessException);
uinGeneratorStage.process(messageDTO);
}


@Test
public void testHttpServerErrorException() throws Exception {

Expand All @@ -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());

Expand All @@ -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());
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -1924,7 +1923,7 @@ public void testUpdateSuccess() throws Exception {
assertFalse(result.getInternalError());
}


@Test
public void testUpdateWithoutIdResponseDto() throws Exception {
Map<String, String> fieldMap = new HashMap<>();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -2013,7 +2012,7 @@ public void testUpdateunsuccess() throws Exception {
assertFalse(result.getIsValid());
}

@Ignore
@Ignore
@Test
public void testUinAlreadyExists() throws Exception {
Map<String, String> fieldMap = new HashMap<>();
Expand Down Expand Up @@ -2168,7 +2167,7 @@ public void testJsonProcessingException() throws ApisResourceAccessException, IO
MessageDTO result = uinGeneratorStage.process(messageDTO);
assertTrue(result.getInternalError());
}

@Test
public void testIdRecordExistTrueFlagWithErrorResponse() throws Exception {

Expand Down Expand Up @@ -2664,4 +2663,73 @@ public void testUinGenerationSuccessWithoutUINwithErrorAsEmpty() throws Exceptio
MessageDTO result = uinGeneratorStage.process(messageDTO);
assertFalse(result.getInternalError());
}
}

@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<VidResponseDto> responseVid = new ResponseWrapper<VidResponseDto>();
List<ErrorDTO> 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<String, String> fieldMap = new HashMap<>();
fieldMap.put("firstName","[ {\n" +
" \"language\" : \"eng\",\n" +
" \"value\" : \" \"\n" +
"} ]");
fieldMap.put("email", "[email protected]");
fieldMap.put("phone", "23456");
fieldMap.put("dob", "11/11/2011");

List<String> 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<IdRequestDto> argumentCaptor = ArgumentCaptor.forClass(IdRequestDto.class);

MessageDTO result = uinGeneratorStage.process(messageDTO);
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,21 @@ 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();
}
}
}
}

return value;
}

Expand Down Expand Up @@ -140,8 +145,14 @@ private static String[] getLanguages(JsonValue[] jsonNode, StringBuilder languag
* the reg id
* @return the list
*/

public static List<IndividualDemographicDedupeEntity> converDemographicDedupeDtoToEntity(
IndividualDemographicDedupe demoDto, String regId) throws NoSuchAlgorithmException {

return converDemographicDedupeDtoToEntity(demoDto,regId,false);
}
public static List<IndividualDemographicDedupeEntity> converDemographicDedupeDtoToEntity(
IndividualDemographicDedupe demoDto, String regId,Boolean istrim) throws NoSuchAlgorithmException {
regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), regId,
"PacketInfoMapper::converDemographicDedupeDtoToEntity()::entry");
IndividualDemographicDedupeEntity entity;
Expand All @@ -168,7 +179,7 @@ public static List<IndividualDemographicDedupeEntity> 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())
Expand All @@ -187,7 +198,7 @@ public static List<IndividualDemographicDedupeEntity> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public class PacketInfoManagerImpl implements PacketInfoManager<Identity, Applic
@Value("${registration.processor.demodedupe.manualverification.status}")
private String manualVerificationStatus;

@Value("${mosip.regproc.demo.dedupe.trim-whitespaces.simpleType-value:false}")
private boolean trimWhitespace;

/** The Constant MATCHED_REFERENCE_TYPE. */
private static final String MATCHED_REFERENCE_TYPE = "rid";

Expand Down Expand Up @@ -297,7 +300,7 @@ private void saveIndividualDemographicDedupe(String regId, String process, LogDe

try {
List<IndividualDemographicDedupeEntity> applicantDemographicEntities = PacketInfoMapper
.converDemographicDedupeDtoToEntity(demographicData, regId);
.converDemographicDedupeDtoToEntity(demographicData, regId,trimWhitespace);
for (IndividualDemographicDedupeEntity applicantDemographicEntity : applicantDemographicEntities) {
demographicDedupeRepository.save(applicantDemographicEntity);

Expand Down Expand Up @@ -343,7 +346,8 @@ public void saveIndividualDemographicDedupeUpdatePacket(IndividualDemographicDed

try {
List<IndividualDemographicDedupeEntity> applicantDemographicEntities = PacketInfoMapper
.converDemographicDedupeDtoToEntity(demographicData, registrationId);
.converDemographicDedupeDtoToEntity(demographicData, registrationId, trimWhitespace);

for (IndividualDemographicDedupeEntity applicantDemographicEntity : applicantDemographicEntities) {
demographicDedupeRepository.save(applicantDemographicEntity);

Expand Down
Loading

0 comments on commit 2a0a001

Please sign in to comment.