Skip to content

Commit

Permalink
Merge pull request #1798 from Khuddusshariff0022/1.1.5.5_MOSIP_30470_…
Browse files Browse the repository at this point in the history
…UIN_Generation_failed_Invalid_Input_Parameter

MOSIP-30470 code changes
  • Loading branch information
vishwa-vyom authored Dec 6, 2023
2 parents 4fabb80 + 270adec commit d987c3a
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public class UinGeneratorStage extends MosipVerticleAPIManager {
private static final String OLD_APPLICATION_ID = "IDR-IDC-011";
private static final String RECORD_ALREADY_EXISTS_ERROR = "IDR-IDC-012";

private static final String INVALID_INPUT_PARAMETER_ERROR_CODE="IDR-IDC-002";


@Autowired
private Environment env;
Expand Down Expand Up @@ -159,6 +161,9 @@ public class UinGeneratorStage extends MosipVerticleAPIManager {
@Value("${mosip.regproc.uin.generator.dob.log.enable:false}")
private boolean dobLogEnable;

@Value("${mosip.regproc.uin.generator.idrepo-max-retry-count}")
Integer maxRetrycount;

/** The core audit request builder. */
@Autowired
private AuditLogRequestBuilder auditLogRequestBuilder;
Expand Down Expand Up @@ -238,16 +243,13 @@ public MessageDTO process(MessageDTO object) {
if (matchedRegId != null) {
linkRegIdWrtUin(lostPacketRegId, matchedRegId, registrationStatusDto.getRegistrationType(), object, description);
}

} else {

IdResponseDTO idResponseDTO = new IdResponseDTO();
String schemaVersion = packetManagerService.getFieldByMappingJsonKey(registrationId, MappingJsonConstants.IDSCHEMA_VERSION, registrationStatusDto.getRegistrationType(), ProviderStageName.UIN_GENERATOR);

Map<String, String> fieldMap = packetManagerService.getFields(registrationId,
idSchemaUtil.getDefaultFields(Double.valueOf(schemaVersion)), registrationStatusDto.getRegistrationType(), ProviderStageName.UIN_GENERATOR);
String uinField = fieldMap.get(utility.getMappingJsonValue(MappingJsonConstants.UIN, MappingJsonConstants.IDENTITY));

String dateOfBirth = fieldMap
.get(utility.getMappingJsonValue(MappingJsonConstants.DOB, MappingJsonConstants.IDENTITY));
if ((dateOfBirth != null && !dateOfBirth.isEmpty()) && dobLogEnable) {
Expand All @@ -268,19 +270,23 @@ public MessageDTO process(MessageDTO object) {

String test = (String) registrationProcessorRestClientService.getApi(ApiName.UINGENERATOR, null, "",
"", String.class);

regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(),
registrationId, "Received response from UINGENERATOR API");

Gson gsonObj = new Gson();
uinResponseDto = gsonObj.fromJson(test, UinGenResponseDto.class);

uinField = uinResponseDto.getResponse().getUin();
demographicIdentity.put("UIN", uinField);

idResponseDTO = sendIdRepoWithUin(registrationId, registrationStatusDto.getRegistrationType(), demographicIdentity,
uinField, description);
if(idResponseDTO.getErrors()!=null && idResponseDTO.getErrors().get(0).getErrorCode().equalsIgnoreCase(INVALID_INPUT_PARAMETER_ERROR_CODE)) {
for (int i = 0; i < maxRetrycount; i++) {
idResponseDTO = sendIdRepoWithUin(registrationId, registrationStatusDto.getRegistrationType(), demographicIdentity,
uinField, description);
if (idResponseDTO.getErrors()==null || idResponseDTO.getErrors().get(0).getErrorCode()!=INVALID_INPUT_PARAMETER_ERROR_CODE)
break;

}
}
boolean isUinAlreadyPresent = isUinAlreadyPresent(idResponseDTO, registrationId);

if (isIdResponseNotNull(idResponseDTO) || isUinAlreadyPresent) {
Expand All @@ -292,7 +298,6 @@ public MessageDTO process(MessageDTO object) {
}else {
handleIdRepoSuccessResponse(registrationStatusDto, registrationId, isUinAlreadyPresent, isTransactionSuccessful, uinResponseDto, object, description);
}

}else {
handleIdRepoErrorResponse(idResponseDTO, registrationStatusDto, registrationId, isTransactionSuccessful, uinResponseDto, object, description);
}
Expand All @@ -312,13 +317,12 @@ public MessageDTO process(MessageDTO object) {
description);
}
}

}
regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(),
registrationId, description.getMessage());
registrationStatusDto.setUpdatedBy(UINConstants.USER);

} catch (io.mosip.kernel.core.util.exception.JsonProcessingException e) {
}
catch (io.mosip.kernel.core.util.exception.JsonProcessingException e) {
regProcLogger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(),
registrationId,
RegistrationStatusCode.FAILED.toString() + e.getMessage() + ExceptionUtils.getStackTrace(e));
Expand Down Expand Up @@ -567,26 +571,30 @@ private void handleIdRepoErrorResponse(IdResponseDTO idResponseDTO, InternalRegi
String registrationId,boolean isTransactionSuccessful,
UinGenResponseDto uinResponseDto,MessageDTO object, LogDescription description) throws ApisResourceAccessException, IOException{
List<ErrorDTO> errors = idResponseDTO != null ? idResponseDTO.getErrors() : null;

String statusComment = errors != null ? errors.get(0).getMessage() : UINConstants.NULL_IDREPO_RESPONSE;

if(errors!=null && errors.get(0).getErrorCode().equalsIgnoreCase(RECORD_ALREADY_EXISTS_ERROR)) {
registrationStatusDto.setStatusCode(RegistrationTransactionStatusCode.ERROR.toString());
registrationStatusDto.setLatestTransactionStatusCode(
RegistrationTransactionStatusCode.IN_PROGRESS.toString());
registrationStatusDto.setStatusComment(StatusUtil.UIN_ALREADY_EXIST_IN_IDREPO.getMessage());
registrationStatusDto.setSubStatusCode(StatusUtil.UIN_ALREADY_EXIST_IN_IDREPO.getCode());
description.setTransactionStatusCode(RegistrationTransactionStatusCode.IN_PROGRESS.toString());

}else if(errors!=null && errors.get(0).getErrorCode().equalsIgnoreCase(OLD_APPLICATION_ID)) {
registrationStatusDto.setStatusComment(StatusUtil.OLD_APPLICATION_ID.getMessage());
registrationStatusDto.setStatusCode(RegistrationTransactionStatusCode.FAILED.toString());
registrationStatusDto
.setLatestTransactionStatusCode(RegistrationTransactionStatusCode.FAILED.toString());
registrationStatusDto.setSubStatusCode(StatusUtil.OLD_APPLICATION_ID.getCode());
description.setTransactionStatusCode(RegistrationTransactionStatusCode.FAILED.toString());

}else {

} else if (errors!=null && errors.get(0).getErrorCode().equalsIgnoreCase(INVALID_INPUT_PARAMETER_ERROR_CODE)) {
registrationStatusDto.setStatusCode(RegistrationTransactionStatusCode.PROCESSING.toString());
registrationStatusDto.setLatestTransactionStatusCode(
RegistrationTransactionStatusCode.REPROCESS.toString());
registrationStatusDto.setStatusComment(StatusUtil.INVALID_INPUT_PARAMETER.getMessage());
registrationStatusDto.setSubStatusCode(StatusUtil.INVALID_INPUT_PARAMETER.getCode());
description.setTransactionStatusCode(RegistrationTransactionStatusCode.REPROCESS.toString());
} else {
registrationStatusDto.setStatusComment(trimExceptionMessage
.trimExceptionMessage(StatusUtil.UIN_GENERATION_FAILED.getMessage() + statusComment));
registrationStatusDto.setSubStatusCode(StatusUtil.UIN_GENERATION_FAILED.getCode());
Expand Down Expand Up @@ -1113,7 +1121,6 @@ public void start() {
router.setRoute(this.postUrl(getVertx(), MessageBusAddress.UIN_GENERATION_BUS_IN,
MessageBusAddress.UIN_GENERATION_BUS_OUT));
this.createServer(router.getRouter(), Integer.parseInt(port));

}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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 @@ -25,6 +25,7 @@
import java.util.List;
import java.util.Map;

import io.mosip.registration.processor.core.status.util.StatusUtil;
import org.apache.commons.io.IOUtils;
import org.assertj.core.util.Lists;
import org.json.JSONException;
Expand All @@ -33,14 +34,12 @@
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.*;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.test.util.ReflectionTestUtils;
Expand Down Expand Up @@ -229,11 +228,14 @@ public void consumeAndSend(MosipEventBus mosipEventBus, MessageBusAddress fromAd
@Mock
private IdSchemaUtil idSchemaUtil;



@Before
public void setup() throws Exception {
ReflectionTestUtils.setField(uinGeneratorStage, "workerPoolSize", 10);
ReflectionTestUtils.setField(uinGeneratorStage, "messageExpiryTimeLimit", Long.valueOf(0));
ReflectionTestUtils.setField(uinGeneratorStage, "clusterManagerUrl", "/dummyPath");
ReflectionTestUtils.setField(uinGeneratorStage, "maxRetrycount", 3);

ClassLoader classLoader1 = getClass().getClassLoader();
File idJsonFile1 = new File(classLoader1.getResource("RegistrationProcessorIdentity.json").getFile());
Expand Down Expand Up @@ -390,7 +392,6 @@ public void testUinGenerationSuccessWithoutUIN() throws Exception {

MessageDTO result = uinGeneratorStage.process(messageDTO);
assertFalse(result.getInternalError());

}

@Test
Expand Down Expand Up @@ -429,6 +430,7 @@ public void testUinGenerationResponseNull() throws Exception {
MessageDTO result = uinGeneratorStage.process(messageDTO);
//assertFalse(result.getInternalError());
}

@Test
public void testUinGenerationF() throws Exception {
MessageDTO messageDTO = new MessageDTO();
Expand Down Expand Up @@ -474,6 +476,7 @@ public void testUinGenerationF() throws Exception {

}


@Test
public void testUinGenerationSuccessWithoutUINAndUinUnused() throws Exception {
MessageDTO messageDTO = new MessageDTO();
Expand Down Expand Up @@ -2479,4 +2482,142 @@ public void testSuccessfullIdResponseWithUinAndRid() throws Exception {

}

/**
* In this method Invalid input parameter is thrown 2 time. then 3rd time will get the positive response.
*
*/
@Test
public void testUinGenerationResponseWithInvalidInputParameterExceptionForFirstThreeTimes() throws Exception {
MessageDTO messageDTO = new MessageDTO();
messageDTO.setRid("27847657360002520181210094052");
messageDTO.setReg_type(RegistrationType.NEW);
String str = "{\n" +
" \"id\": \"mosip.id.read\",\n" +
" \"version\": \"1.0\",\n" +
" \"responsetime\": \"2019-04-05\",\n" +
" \"metadata\": null,\n" +
" \"response\": {},\n" +
" \"errors\": [\n" +
" {\n" +
" \"errorCode\": \"IDR-IDC-002\",\n" +
" \"errorMessage\": \"Invalid Input Parameter\"\n" +
" }\n" +
" ]\n" +
"}";
String response = "{\n" +
" \"id\": \"mosip.id.read\",\n" +
" \"version\": \"1.0\",\n" +
" \"responsetime\": \"2019-04-05\",\n" +
" \"metadata\": null,\n" +
" \"response\": {},\n" +
" \"errors\": [\n" +
" {\n" +
" \"errorCode\": \"IDR-IDC-002\",\n" +
" \"errorMessage\": \"Invalid Input Parameter\"\n" +
" }\n" +
" ]\n" +
"}";
when(registrationProcessorRestClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(str);
when(registrationProcessorRestClientService.putApi(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(response);

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

ResponseWrapper<VidResponseDto> responseVid = new ResponseWrapper<VidResponseDto>();
List<ErrorDTO> errors = new ArrayList<>();
ErrorDTO errorDTO=new ErrorDTO("IDR-IDC-002", StatusUtil.INVALID_INPUT_PARAMETER.getMessage());
errors.add(errorDTO);
idResponseDTO.setErrors(errors);
idResponseDTO.setVersion("v12");
idResponseDTO.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);

IdResponseDTO positiveidResponseDTO = new IdResponseDTO();
ResponseDTO responseDTO1 = new ResponseDTO();
responseDTO1.setEntity("https://dev.mosip.io/idrepo/v1.0/identity/203560486746");
responseDTO1.setStatus("ACTIVATED");
positiveidResponseDTO.setErrors(null);
positiveidResponseDTO.setId("mosip.id.create");
positiveidResponseDTO.setResponse(responseDTO1);
positiveidResponseDTO.setResponsetime("2019-01-17T06:29:01.940Z");
positiveidResponseDTO.setVersion("1.0");

when(registrationProcessorRestClientService.postApi(any(), any(), any(), any(), any(Class.class)))
.thenReturn(idResponseDTO)
.thenReturn(idResponseDTO)
.thenReturn(idResponseDTO)
.thenReturn(positiveidResponseDTO)
.thenReturn(responseVid);
MessageDTO result = uinGeneratorStage.process(messageDTO);
assertFalse(result.getInternalError());
assertTrue(result.getIsValid());
}


/*
In this test case each time when Uin_generator api is called Invalid input parameter is the responde.
*/
@Test
public void testUinGenerationResponseWillExcedesRetryCount() throws Exception {
MessageDTO messageDTO = new MessageDTO();
messageDTO.setRid("27847657360002520181210094052");
messageDTO.setReg_type(RegistrationType.NEW);
String str = "{\n" +
" \"id\": \"mosip.id.read\",\n" +
" \"version\": \"1.0\",\n" +
" \"responsetime\": \"2019-04-05\",\n" +
" \"metadata\": null,\n" +
" \"response\": {},\n" +
" \"errors\": [\n" +
" {\n" +
" \"errorCode\": \"IDR-IDC-002\",\n" +
" \"errorMessage\": \"Invalid Input Parameter\"\n" +
" }\n" +
" ]\n" +
"}";
String response = "{\n" +
" \"id\": \"mosip.id.read\",\n" +
" \"version\": \"1.0\",\n" +
" \"responsetime\": \"2019-04-05\",\n" +
" \"metadata\": null,\n" +
" \"response\": {},\n" +
" \"errors\": [\n" +
" {\n" +
" \"errorCode\": \"IDR-IDC-002\",\n" +
" \"errorMessage\": \"Invalid Input Parameter\"\n" +
" }\n" +
" ]\n" +
"}";
when(registrationProcessorRestClientService.getApi(any(), any(), anyString(), any(), any())).thenReturn(str);
when(registrationProcessorRestClientService.putApi(any(), any(), any(), any(), any(), any(), any()))
.thenReturn(response);

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

List<ErrorDTO> errors = new ArrayList<>();
ErrorDTO errorDTO=new ErrorDTO("IDR-IDC-002", StatusUtil.INVALID_INPUT_PARAMETER.getMessage());
errors.add(errorDTO);
idResponseDTO.setErrors(errors);
idResponseDTO.setVersion("v12");
idResponseDTO.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);


when(registrationProcessorRestClientService.postApi(any(), any(), any(), any(), any(Class.class)))
.thenReturn(idResponseDTO)
.thenReturn(idResponseDTO)
.thenReturn(idResponseDTO)
.thenReturn(idResponseDTO);

when(registrationStatusService.getRegistrationStatus(any())).thenReturn(registrationStatusDto);
MessageDTO result = uinGeneratorStage.process(messageDTO);
assertTrue(result.getInternalError());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public enum StatusUtil {
LINK_RID_FOR_LOST_PACKET_FAILED(StatusConstants.UIN_GENERATOR_MODULE_FAILED + "008","UIn not found the the matched RID"),
UIN_ALREADY_EXIST_IN_IDREPO(StatusConstants.UIN_GENERATOR_MODULE_FAILED + "009", "Received ID record already exists error from idrepo even after trying with force merge"),
OLD_APPLICATION_ID(StatusConstants.UIN_GENERATOR_MODULE_FAILED + "010","Received error as old application ID reprocessing not allowed from idrepo"),

INVALID_INPUT_PARAMETER(StatusConstants.UIN_GENERATOR_MODULE_FAILED+"011","Received error as Invalid Input Parameter"),
//Request handler service
//1)Resident UIN update
RESIDENT_UPDATE_SUCCES(StatusConstants.REQUEST_HANDLER_MODULE_SUCCESS + "001" , "Resident Uin data updated sucessfully"),
Expand Down

0 comments on commit d987c3a

Please sign in to comment.