Skip to content

Commit

Permalink
Merge pull request #1931 from Khuddusshariff0022/release-1.2.0.x_addi…
Browse files Browse the repository at this point in the history
…ng_to_release

[ MOSIP-35378 ] Release 1.2.0.x adding to release
  • Loading branch information
ckm007 authored Nov 8, 2024
2 parents ab19b8c + cdc871a commit 9c0d704
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,35 +463,48 @@ public MessageDTO process(MessageDTO object) {
return object;
}

private void loadDemographicIdentity(Map<String, String> fieldMap, JSONObject demographicIdentity) throws IOException, JSONException {
for (Map.Entry e : fieldMap.entrySet()) {
if (e.getValue() != null) {
String value = e.getValue().toString();
if (value != null) {
Object json = new JSONTokener(value).nextValue();
if (json instanceof org.json.JSONObject) {
HashMap<String, Object> hashMap = objectMapper.readValue(value, HashMap.class);
demographicIdentity.putIfAbsent(e.getKey(), hashMap);
}
else if (json instanceof JSONArray) {
List jsonList = new ArrayList<>();
JSONArray jsonArray = new JSONArray(value);
for (int i = 0; i < jsonArray.length(); i++) {
Object obj = jsonArray.get(i);
HashMap<String, Object> hashMap = 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);
} else
demographicIdentity.putIfAbsent(e.getKey(), value);
} else
demographicIdentity.putIfAbsent(e.getKey(), value);
}
}
}
private void loadDemographicIdentity(Map<String, String> fieldMap, JSONObject demographicIdentity) throws IOException, JSONException {
for (Map.Entry e : fieldMap.entrySet()) {
if (e.getValue() == null) {
continue;
}

String value = e.getValue().toString();
if (value == null) {
demographicIdentity.putIfAbsent(e.getKey(), value);
continue;
}

Object json = new JSONTokener(value).nextValue();
if (json instanceof org.json.JSONObject) {
HashMap<String, Object> hashMap = objectMapper.readValue(value, HashMap.class);
demographicIdentity.putIfAbsent(e.getKey(), hashMap);
continue;
}

if (json instanceof JSONArray) {
List jsonList = new ArrayList<>();
JSONArray jsonArray = new JSONArray(value);
for (int i = 0; i < jsonArray.length(); i++) {
Object obj = jsonArray.get(i);
if (obj instanceof String) {
jsonList.add(obj);
} else {
HashMap<String, Object> hashMap = objectMapper.readValue(obj.toString(), HashMap.class);

if (trimWhitespaces && hashMap.containsKey("value") && hashMap.get("value") instanceof String) {
hashMap.put("value", ((String) hashMap.get("value")).trim());
}
jsonList.add(hashMap);
}
}
demographicIdentity.putIfAbsent(e.getKey(), jsonList);
}
else {
demographicIdentity.putIfAbsent(e.getKey(), value);
}
}
}

/**
* Send id repo with uin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2475,4 +2475,92 @@ public void testUinGenerationSuccessWithEmptyName() throws Exception {
assertFalse(result.getInternalError());
assertTrue(result.getIsValid());
}

@Test
public void testUinGenerationSuccessWithSelectedHanhle() throws Exception {
ReflectionTestUtils.setField(uinGeneratorStage,"trimWhitespaces",true);
Map<String, String> fieldMap = new HashMap<>();
fieldMap.put("selectedHandles","[\n" +
" \"nrcId\",\n" +
" \"email\",\n" +
" \"phoneNumber\"\n" +
" ]");
fieldMap.put("email", "[email protected]");
fieldMap.put("phoneNumber", "23456");
fieldMap.put("dob", "11/11/2011");
when(packetManagerService.getFields(any(),any(),any(),any())).thenReturn(fieldMap);
ArgumentCaptor<io.mosip.registration.processor.packet.manager.dto.IdRequestDto> argumentCaptor = ArgumentCaptor.forClass(IdRequestDto.class);

MessageDTO messageDTO = new MessageDTO();
messageDTO.setRid("27847657360002520181210094052");
messageDTO.setReg_type(RegistrationType.NEW.name());

IdResponseDTO idResponseDTO = new IdResponseDTO();
ResponseDTO responseDTO = new ResponseDTO();
responseDTO.setStatus("ACTIVATED");
idResponseDTO.setErrors(null);
idResponseDTO.setId("mosip.id.update");
idResponseDTO.setResponse(responseDTO);
idResponseDTO.setResponsetime("2019-01-17T06:29:01.940Z");
idResponseDTO.setVersion("1.0");

when(idrepoDraftService.idrepoUpdateDraft(anyString(), any(), any())).thenReturn(idResponseDTO);
when(utility.getRegistrationProcessorMappingJson(MappingJsonConstants.IDENTITY)).thenReturn(identityObj);
when(utility.getRegistrationProcessorMappingJson(MappingJsonConstants.DOCUMENT)).thenReturn(documentObj);

MessageDTO result = uinGeneratorStage.process(messageDTO);
verify(idrepoDraftService).idrepoUpdateDraft(any(), any(), argumentCaptor.capture());
ObjectMapper objectMapper = new ObjectMapper();
String jsonobject=objectMapper.writeValueAsString(argumentCaptor.getAllValues().get(0).getRequest().getIdentity());
JsonNode jsonNode=objectMapper.readTree(jsonobject);

assertEquals("nrcId",jsonNode.get("selectedHandles").get(0).asText());
assertEquals("email",jsonNode.get("selectedHandles").get(1).asText());
assertEquals("phoneNumber",jsonNode.get("selectedHandles").get(2).asText());
assertFalse(result.getInternalError());
assertTrue(result.getIsValid());
}

@Test
public void testUinGenerationSuccessWithObjectDataType () throws Exception {
ReflectionTestUtils.setField(uinGeneratorStage,"trimWhitespaces",true);
Map<String, String> fieldMap = new HashMap<>();
fieldMap.put("individualBiometrics","{\n" +
" \"format\": \"cbeff\",\n" +
" \"value\": \"individualBiometrics_bio_CBEFF\",\n" +
" \"version\": 1\n" +
" }");
fieldMap.put("email", "[email protected]");
fieldMap.put("phoneNumber", "23456");
fieldMap.put("dob", "11/11/2011");
when(packetManagerService.getFields(any(),any(),any(),any())).thenReturn(fieldMap);
ArgumentCaptor<io.mosip.registration.processor.packet.manager.dto.IdRequestDto> argumentCaptor = ArgumentCaptor.forClass(IdRequestDto.class);

MessageDTO messageDTO = new MessageDTO();
messageDTO.setRid("27847657360002520181210094052");
messageDTO.setReg_type(RegistrationType.NEW.name());

IdResponseDTO idResponseDTO = new IdResponseDTO();
ResponseDTO responseDTO = new ResponseDTO();
responseDTO.setStatus("ACTIVATED");
idResponseDTO.setErrors(null);
idResponseDTO.setId("mosip.id.update");
idResponseDTO.setResponse(responseDTO);
idResponseDTO.setResponsetime("2019-01-17T06:29:01.940Z");
idResponseDTO.setVersion("1.0");

when(idrepoDraftService.idrepoUpdateDraft(anyString(), any(), any())).thenReturn(idResponseDTO);
when(utility.getRegistrationProcessorMappingJson(MappingJsonConstants.IDENTITY)).thenReturn(identityObj);
when(utility.getRegistrationProcessorMappingJson(MappingJsonConstants.DOCUMENT)).thenReturn(documentObj);

MessageDTO result = uinGeneratorStage.process(messageDTO);
verify(idrepoDraftService).idrepoUpdateDraft(any(), any(), argumentCaptor.capture());
ObjectMapper objectMapper = new ObjectMapper();
String jsonobject=objectMapper.writeValueAsString(argumentCaptor.getAllValues().get(0).getRequest().getIdentity());
JsonNode jsonNode=objectMapper.readTree(jsonobject);

assertEquals("cbeff",jsonNode.get("individualBiometrics").get("format").asText());
assertFalse(result.getInternalError());
assertTrue(result.getIsValid());
}
}

0 comments on commit 9c0d704

Please sign in to comment.