Skip to content

Commit

Permalink
[Mosip-30240]Release 1.2.0.1 mosip 30240 (#1840)
Browse files Browse the repository at this point in the history
* Merge pull request #1831 from Khuddusshariff0022/develop_Mosip_30241

MOSIP-30241 adding trim functionality based on property.

Signed-off-by: khuddus shariff <[email protected]>

* [Mosip-30241] Merge pull request #1831 from Khuddusshariff0022/develop-Mosip_30241

Signed-off-by: khuddus shariff <[email protected]>

---------

Signed-off-by: khuddus shariff <[email protected]>
Co-authored-by: Vishwa <[email protected]>
  • Loading branch information
Khuddusshariff0022 and vishwa-vyom authored Jan 24, 2024
1 parent 4137411 commit 1d4ce75
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ public class UinGeneratorStage extends MosipVerticleAPIManager {
@Value("${uingenerator.lost.packet.allowed.update.fields:null}")
private String updateInfo;

@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 @@ -323,7 +326,6 @@ public MessageDTO process(MessageDTO object) {
description);
}
}

}
regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(),
registrationId, description.getMessage());
Expand Down Expand Up @@ -477,6 +479,9 @@ else if (json instanceof JSONArray) {
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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.when;
import static org.mockito.Mockito.*;

import java.io.ByteArrayInputStream;
import java.io.File;
Expand All @@ -15,13 +14,19 @@
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 @@ -30,11 +35,7 @@
import org.junit.Ignore;
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.Spy;
import org.mockito.*;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
Expand Down Expand Up @@ -144,13 +145,13 @@ public void send(MessageBusAddress toAddress, MessageDTO message) {

@Override
public void consumerHealthCheck(Handler<HealthCheckDTO> eventHandler, String address) {
// TODO Auto-generated method stub


}

@Override
public void senderHealthCheck(Handler<HealthCheckDTO> eventHandler, String address) {
// TODO Auto-generated method stub


}

Expand Down Expand Up @@ -2432,4 +2433,46 @@ public void testUinGenerationIDRepoDraftReprocessableException() throws Exceptio
assertTrue(result.getInternalError());
assertTrue(result.getIsValid());
}

@Test
public void testUinGenerationSuccessWithEmptyName() throws Exception {
ReflectionTestUtils.setField(uinGeneratorStage,"trimWhitespaces",true);
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");
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("",jsonNode.get("firstName").asText());
assertFalse(result.getInternalError());
assertTrue(result.getIsValid());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
}
Expand Down Expand Up @@ -115,6 +120,11 @@ private static String[] getLanguages(JsonValue[] jsonNode, StringBuilder languag
*/
public static List<IndividualDemographicDedupeEntity> converDemographicDedupeDtoToEntity(
IndividualDemographicDedupe demoDto, String regId,String process, int iteration, String workflowInstanceId) throws NoSuchAlgorithmException {

return converDemographicDedupeDtoToEntity(demoDto,regId,process,iteration,workflowInstanceId,false);
}
public static List<IndividualDemographicDedupeEntity> converDemographicDedupeDtoToEntity(
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;
Expand Down Expand Up @@ -144,7 +154,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 @@ -163,7 +173,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 @@ -141,6 +141,9 @@ public class PacketInfoManagerImpl implements PacketInfoManager<Identity, Applic
@Value("${registration.processor.demodedupe.manual.adjudication.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 @@ -293,7 +296,7 @@ private void saveIndividualDemographicDedupe(String regId, String process, LogDe

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

Expand Down Expand Up @@ -339,7 +342,7 @@ public void saveIndividualDemographicDedupeUpdatePacket(IndividualDemographicDed

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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<IndividualDemographicDedupeEntity> 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<Integer> arg2 = ArgumentCaptor.forClass(Integer.class);
packetInfoManagerImpl.saveIndividualDemographicDedupeUpdatePacket(demographicData,
"1001", "","NEW", "",1, "");
}
}

0 comments on commit 1d4ce75

Please sign in to comment.