Skip to content

Commit

Permalink
Merge pull request #1788 from sowmya695/MOSIP-29780_develop
Browse files Browse the repository at this point in the history
Mosip 29780 develop

Signed-off-by: Sowmya Ujjappa Banakar <[email protected]>
  • Loading branch information
vishwa-vyom authored and Sowmya Ujjappa Banakar committed Jan 24, 2024
1 parent c3b8646 commit 3f19df8
Show file tree
Hide file tree
Showing 12 changed files with 1,673 additions and 1,473 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.core.MediaType;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -52,6 +50,7 @@
import io.mosip.registration.processor.core.util.RegistrationExceptionMapperUtil;
import io.mosip.registration.processor.packet.manager.dto.IdResponseDTO;
import io.mosip.registration.processor.packet.manager.exception.IdrepoDraftException;
import io.mosip.registration.processor.packet.manager.exception.IdrepoDraftReprocessableException;
import io.mosip.registration.processor.packet.manager.idreposervice.IdrepoDraftService;
import io.mosip.registration.processor.rest.client.audit.builder.AuditLogRequestBuilder;
import io.mosip.registration.processor.status.code.RegistrationStatusCode;
Expand All @@ -76,6 +75,7 @@ public class BiometricExtractionStage extends MosipVerticleAPIManager{
/** stage properties prefix */
private static final String STAGE_PROPERTY_PREFIX = "mosip.regproc.biometric.extraction.";
private static final String USER = "MOSIP_SYSTEM";
private static final String ID_REPO_KEY_MANAGER_ERROR = "IDR-IDS-003";

/** The mosip event bus. */
MosipEventBus mosipEventBus = null;
Expand Down Expand Up @@ -267,14 +267,31 @@ public MessageDTO process(MessageDTO object) {
RegistrationStatusCode.FAILED.toString() + e.getMessage() + ExceptionUtils.getStackTrace(e));
registrationStatusDto.setStatusCode(RegistrationStatusCode.FAILED.name());
registrationStatusDto.setStatusComment(
trimExceptionMessage.trimExceptionMessage(StatusUtil.IDREPO_DRAFT_EXCEPTION.getMessage() + e.getMessage()));
registrationStatusDto.setSubStatusCode(StatusUtil.IDREPO_DRAFT_EXCEPTION.getCode());
trimExceptionMessage.trimExceptionMessage(
StatusUtil.BIOMETRIC_EXTRACTION_IDREPO_DRAFT_EXCEPTION.getMessage() + e.getMessage()));
registrationStatusDto.setSubStatusCode(StatusUtil.BIOMETRIC_EXTRACTION_IDREPO_DRAFT_EXCEPTION.getCode());
registrationStatusDto.setLatestTransactionStatusCode(
registrationStatusMapperUtil.getStatusCode(RegistrationExceptionTypeCode.IDREPO_DRAFT_EXCEPTION));
description.setMessage(PlatformErrorMessages.IDREPO_DRAFT_EXCEPTION.getMessage());
description.setCode(PlatformErrorMessages.IDREPO_DRAFT_EXCEPTION.getCode());
object.setInternalError(Boolean.TRUE);
object.setRid(registrationStatusDto.getRegistrationId());
} catch (IdrepoDraftReprocessableException e) {
regProcLogger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(),
registrationId,
RegistrationStatusCode.PROCESSING.toString() + e.getMessage() + ExceptionUtils.getStackTrace(e));
registrationStatusDto.setStatusCode(RegistrationStatusCode.PROCESSING.name());
registrationStatusDto.setStatusComment(trimExceptionMessage.trimExceptionMessage(
StatusUtil.BIOMETRIC_EXTRACTION_IDREPO_DRAFT_REPROCESSABLE_EXCEPTION.getMessage()
+ e.getMessage()));
registrationStatusDto
.setSubStatusCode(StatusUtil.BIOMETRIC_EXTRACTION_IDREPO_DRAFT_REPROCESSABLE_EXCEPTION.getCode());
registrationStatusDto.setLatestTransactionStatusCode(registrationStatusMapperUtil
.getStatusCode(RegistrationExceptionTypeCode.IDREPO_DRAFT_REPROCESSABLE_EXCEPTION));
description.setMessage(PlatformErrorMessages.IDREPO_DRAFT_EXCEPTION.getMessage());
description.setCode(PlatformErrorMessages.IDREPO_DRAFT_EXCEPTION.getCode());
object.setInternalError(Boolean.TRUE);
object.setRid(registrationStatusDto.getRegistrationId());
}catch (Exception ex) {
registrationStatusDto.setStatusCode(RegistrationStatusCode.FAILED.name());
registrationStatusDto.setStatusComment(
Expand Down Expand Up @@ -323,13 +340,17 @@ public MessageDTO process(MessageDTO object) {

/**
* add biometric extractions to id repo
*
* @param dto
* @param registrationId
* @throws ApisResourceAccessException
* @throws RegistrationProcessorCheckedException
* @throws IdrepoDraftReprocessableException
* @throws IdrepoDraftException
*
*/
private IdResponseDTO addBiometricExtractiontoIdRepository(ExtractorDto dto,
String registrationId) throws ApisResourceAccessException, RegistrationProcessorCheckedException {
String registrationId)
throws ApisResourceAccessException, IdrepoDraftReprocessableException, IdrepoDraftException {
String extractionFormat = "";
if(dto.getBiometric().equals("iris")) {
extractionFormat="irisExtractionFormat";
Expand All @@ -340,10 +361,15 @@ private IdResponseDTO addBiometricExtractiontoIdRepository(ExtractorDto dto,
}
List<String> segments=List.of(registrationId);
IdResponseDTO response= (IdResponseDTO) registrationProcessorRestClientService.putApi(ApiName.IDREPOEXTRACTBIOMETRICS, segments, extractionFormat, dto.getAttributeName(), null, IdResponseDTO.class, null);

if (response.getErrors() != null && !response.getErrors().isEmpty()) {
regProcLogger.error("Error occured while updating draft for id : " + registrationId, response.getErrors().iterator().next().toString());
throw new RegistrationProcessorCheckedException(response.getErrors().iterator().next().getErrorCode(),
response.getErrors().iterator().next().getMessage());
ErrorDTO error = response.getErrors().get(0);
regProcLogger.error("Error occured while updating draft for id : " + registrationId, error.toString());
if (response.getErrors().get(0).getErrorCode().equalsIgnoreCase(ID_REPO_KEY_MANAGER_ERROR)) {
throw new IdrepoDraftReprocessableException(error.getErrorCode(), error.getMessage());
} else {
throw new IdrepoDraftException(error.getErrorCode(), error.getMessage());
}
}
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.List;

import org.apache.commons.io.IOUtils;
import org.assertj.core.util.Lists;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -35,6 +36,8 @@
import io.mosip.registration.processor.core.code.EventId;
import io.mosip.registration.processor.core.code.EventName;
import io.mosip.registration.processor.core.code.EventType;
import io.mosip.registration.processor.core.code.RegistrationExceptionTypeCode;
import io.mosip.registration.processor.core.common.rest.dto.ErrorDTO;
import io.mosip.registration.processor.core.constant.RegistrationType;
import io.mosip.registration.processor.core.exception.ApisResourceAccessException;
import io.mosip.registration.processor.core.http.ResponseWrapper;
Expand Down Expand Up @@ -329,4 +332,26 @@ public void testBiometricExtractionDraftException() throws Exception {
public void testDeployVerticle() {
biometricExtractionStage.deployVerticle();
}

@Test
public void testIdrepoDraftReprocessableException() throws Exception {
MessageDTO messageDTO = new MessageDTO();
messageDTO.setRid("27847657360002520181210094052");
messageDTO.setReg_type(RegistrationType.NEW.name());
messageDTO.setWorkflowInstanceId("123er");
messageDTO.setIteration(1);
when(registrationStatusMapperUtil
.getStatusCode(RegistrationExceptionTypeCode.IDREPO_DRAFT_REPROCESSABLE_EXCEPTION))
.thenReturn("REPROCESS");
ErrorDTO errorDTO = new ErrorDTO();
errorDTO.setMessage("Failed to either encrypt/decrypt message using Kernel Crypto Manager");
errorDTO.setErrorCode("IDR-IDS-003");
IdResponseDTO idResponseDTO1 = new IdResponseDTO();
idResponseDTO1.setErrors(Lists.newArrayList(errorDTO));
when(registrationProcessorRestClientService.putApi(any(), any(), anyString(), anyString(), any(), any(), any()))
.thenReturn(idResponseDTO1);
MessageDTO result = biometricExtractionStage.process(messageDTO);
assertTrue(result.getInternalError());
assertTrue(result.getIsValid());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.mosip.registration.processor.core.util.RegistrationExceptionMapperUtil;
import io.mosip.registration.processor.packet.manager.dto.IdResponseDTO;
import io.mosip.registration.processor.packet.manager.exception.IdrepoDraftException;
import io.mosip.registration.processor.packet.manager.exception.IdrepoDraftReprocessableException;
import io.mosip.registration.processor.packet.manager.idreposervice.IdrepoDraftService;
import io.mosip.registration.processor.rest.client.audit.builder.AuditLogRequestBuilder;
import io.mosip.registration.processor.status.code.RegistrationStatusCode;
Expand Down Expand Up @@ -199,14 +200,32 @@ public MessageDTO process(MessageDTO object) {
RegistrationStatusCode.FAILED.toString() + e.getMessage() + ExceptionUtils.getStackTrace(e));
registrationStatusDto.setStatusCode(RegistrationStatusCode.FAILED.name());
registrationStatusDto.setStatusComment(
trimExceptionMessage.trimExceptionMessage(StatusUtil.IDREPO_DRAFT_EXCEPTION.getMessage() + e.getMessage()));
registrationStatusDto.setSubStatusCode(StatusUtil.IDREPO_DRAFT_EXCEPTION.getCode());
trimExceptionMessage.trimExceptionMessage(
StatusUtil.FINALIZATION_IDREPO_DRAFT_EXCEPTION.getMessage() + e.getMessage()));
registrationStatusDto.setSubStatusCode(StatusUtil.FINALIZATION_IDREPO_DRAFT_EXCEPTION.getCode());
registrationStatusDto.setLatestTransactionStatusCode(
registrationStatusMapperUtil.getStatusCode(RegistrationExceptionTypeCode.IDREPO_DRAFT_EXCEPTION));
description.setMessage(PlatformErrorMessages.IDREPO_DRAFT_EXCEPTION.getMessage());
description.setCode(PlatformErrorMessages.IDREPO_DRAFT_EXCEPTION.getCode());
object.setInternalError(Boolean.TRUE);
object.setRid(registrationStatusDto.getRegistrationId());
} catch (IdrepoDraftReprocessableException e) {
regProcLogger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(),
registrationId,
RegistrationStatusCode.PROCESSING.toString() + e.getMessage() + ExceptionUtils.getStackTrace(e));
registrationStatusDto.setStatusCode(RegistrationStatusCode.PROCESSING.name());
registrationStatusDto.setStatusComment(trimExceptionMessage
.trimExceptionMessage(
StatusUtil.FINALIZATION_IDREPO_DRAFT_REPROCESSABLE_EXCEPTION.getMessage()
+ e.getMessage()));
registrationStatusDto
.setSubStatusCode(StatusUtil.FINALIZATION_IDREPO_DRAFT_REPROCESSABLE_EXCEPTION.getCode());
registrationStatusDto.setLatestTransactionStatusCode(registrationStatusMapperUtil
.getStatusCode(RegistrationExceptionTypeCode.IDREPO_DRAFT_REPROCESSABLE_EXCEPTION));
description.setMessage(PlatformErrorMessages.IDREPO_DRAFT_EXCEPTION.getMessage());
description.setCode(PlatformErrorMessages.IDREPO_DRAFT_EXCEPTION.getCode());
object.setInternalError(Boolean.TRUE);
object.setRid(registrationStatusDto.getRegistrationId());
}catch (Exception ex) {
registrationStatusDto.setStatusCode(RegistrationStatusCode.FAILED.name());
registrationStatusDto.setStatusComment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.mosip.registration.processor.core.code.EventId;
import io.mosip.registration.processor.core.code.EventName;
import io.mosip.registration.processor.core.code.EventType;
import io.mosip.registration.processor.core.code.RegistrationExceptionTypeCode;
import io.mosip.registration.processor.core.constant.RegistrationType;
import io.mosip.registration.processor.core.exception.ApisResourceAccessException;
import io.mosip.registration.processor.core.http.ResponseWrapper;
Expand All @@ -37,6 +38,7 @@
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;
import io.mosip.registration.processor.packet.manager.exception.IdrepoDraftReprocessableException;
import io.mosip.registration.processor.packet.manager.idreposervice.IdrepoDraftService;
import io.mosip.registration.processor.rest.client.audit.builder.AuditLogRequestBuilder;
import io.mosip.registration.processor.rest.client.audit.dto.AuditResponseDto;
Expand Down Expand Up @@ -247,4 +249,20 @@ public void testBiometricExtractionUnknownException() throws Exception {
public void testDeployVerticle() {
finalizationStage.deployVerticle();
}

@Test
public void testIdrepoDraftReprocessableException() throws Exception {
MessageDTO messageDTO = new MessageDTO();
messageDTO.setRid("27847657360002520181210094052");
messageDTO.setReg_type(RegistrationType.NEW.name());
messageDTO.setWorkflowInstanceId("123er");
messageDTO.setIteration(1);
when(registrationStatusMapperUtil
.getStatusCode(RegistrationExceptionTypeCode.IDREPO_DRAFT_REPROCESSABLE_EXCEPTION))
.thenReturn("REPROCESS");
when(idrepoDraftService.idrepoPublishDraft(anyString())).thenThrow(IdrepoDraftReprocessableException.class);
MessageDTO result = finalizationStage.process(messageDTO);
assertTrue(result.getInternalError());
assertTrue(result.getIsValid());
}
}
Loading

0 comments on commit 3f19df8

Please sign in to comment.