From 3a06b90816ad3fe2075c15c096056c7e29706380 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Tue, 27 Feb 2024 13:48:57 +0530 Subject: [PATCH 1/6] [MOSIP-31365] Discading draft when there update, extraction, publish Api throughs error. Signed-off-by: khuddus shariff --- .../stage/BiometricExtractionStage.java | 13 +- .../test/BiometricExtractionStageTest.java | 33 +++++- .../finalization/stage/FinalizationStage.java | 2 + .../processor/core/code/ApiName.java | 1 + ...egistrationProcessorRestClientService.java | 5 +- .../idreposervice/IdrepoDraftService.java | 112 +++++++++++------- .../impl/test/IdrepoDraftServiceTest.java | 75 +++++++++++- ...trationProcessorRestClientServiceImpl.java | 54 +++++++++ .../rest/client/utils/RestApiClient.java | 17 +++ ...trationProcessorRestClientServiceTest.java | 47 ++++++-- 10 files changed, 290 insertions(+), 69 deletions(-) diff --git a/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/main/java/io/mosip/registration/processor/stages/biometric/extraction/stage/BiometricExtractionStage.java b/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/main/java/io/mosip/registration/processor/stages/biometric/extraction/stage/BiometricExtractionStage.java index 893abfcee5a..8291d679b35 100644 --- a/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/main/java/io/mosip/registration/processor/stages/biometric/extraction/stage/BiometricExtractionStage.java +++ b/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/main/java/io/mosip/registration/processor/stages/biometric/extraction/stage/BiometricExtractionStage.java @@ -135,7 +135,6 @@ protected String getPropertyPrefix() { * Deploy verticle. */ public void deployVerticle() { - mosipEventBus = this.getEventBus(this, clusterManagerUrl, workerPoolSize); this.consumeAndSend(mosipEventBus, MessageBusAddress.BIOMETRIC_EXTRACTION_BUS_IN, MessageBusAddress.BIOMETRIC_EXTRACTION_BUS_OUT, messageExpiryTimeLimit); @@ -172,8 +171,6 @@ public MessageDTO process(MessageDTO object) { registrationStatusDto .setLatestTransactionTypeCode(RegistrationTransactionTypeCode.BIOMETRIC_EXTRACTION.toString()); registrationStatusDto.setRegistrationStageName(getStageName()); - - if(!idrepoDraftService.idrepoHasDraft(registrationStatusDto.getRegistrationId())) { registrationStatusDto.setStatusCode(RegistrationStatusCode.FAILED.toString()); registrationStatusDto.setLatestTransactionStatusCode(registrationStatusMapperUtil @@ -196,9 +193,9 @@ public MessageDTO process(MessageDTO object) { else { ExtractorsDto extractorsDto=getExtractors(registrationStatusDto.getRegistrationId()); if(extractorsDto.getExtractors()!=null && !extractorsDto.getExtractors().isEmpty()) { - for(ExtractorDto dto:extractorsDto.getExtractors()) { - addBiometricExtractiontoIdRepository(dto,registrationStatusDto.getRegistrationId()); - } + for(ExtractorDto dto:extractorsDto.getExtractors()) { + addBiometricExtractiontoIdRepository(dto,registrationStatusDto.getRegistrationId()); + } } else { throw new RegistrationProcessorCheckedException(PlatformErrorMessages.RPR_PMS_BIOMETRIC_EXTRACTION_NULL_RESPONSE.getCode(), @@ -361,8 +358,8 @@ private IdResponseDTO addBiometricExtractiontoIdRepository(ExtractorDto dto, } List 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()) { + idrepoDraftService.idrepodiscardDraft(registrationId); 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)) { @@ -385,7 +382,7 @@ private IdResponseDTO addBiometricExtractiontoIdRepository(ExtractorDto dto, * @throws JsonParseException * @throws RegistrationProcessorCheckedException */ - private ExtractorsDto getExtractors(String id) throws JSONException, ApisResourceAccessException, JsonParseException, JsonMappingException, JsonProcessingException, IOException, RegistrationProcessorCheckedException { + private ExtractorsDto getExtractors(String id) throws JSONException, ApisResourceAccessException, JsonParseException, JsonMappingException, JsonProcessingException, IOException, RegistrationProcessorCheckedException, IdrepoDraftReprocessableException, IdrepoDraftException { JSONArray jArray=new JSONArray(partnerPolicyIdsJson); ExtractorsDto extractorsDto=new ExtractorsDto(); List errors = new ArrayList<>(); diff --git a/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/test/java/io/mosip/registration/processor/stages/biometric/extraction/stages/test/BiometricExtractionStageTest.java b/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/test/java/io/mosip/registration/processor/stages/biometric/extraction/stages/test/BiometricExtractionStageTest.java index a443b07f2f5..4f3f604eacc 100644 --- a/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/test/java/io/mosip/registration/processor/stages/biometric/extraction/stages/test/BiometricExtractionStageTest.java +++ b/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/test/java/io/mosip/registration/processor/stages/biometric/extraction/stages/test/BiometricExtractionStageTest.java @@ -4,13 +4,15 @@ import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import java.util.ArrayList; import java.util.List; import org.apache.commons.io.IOUtils; +import org.apache.hadoop.yarn.webapp.hamlet.HamletSpec; import org.assertj.core.util.Lists; +import org.json.JSONObject; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -170,8 +172,6 @@ public void setUp() throws Exception { dto.setReg_type("UPDATE"); MockitoAnnotations.initMocks(this); - - ResponseWrapper responseWrapper = new ResponseWrapper<>(); Mockito.doReturn(responseWrapper).when(auditLogRequestBuilder).createAuditRequestBuilder( "test case description", EventId.RPR_405.toString(), EventName.UPDATE.toString(), @@ -356,4 +356,31 @@ public void testIdrepoDraftReprocessableException() throws Exception { assertTrue(result.getInternalError()); assertTrue(result.getIsValid()); } + @Test + public void testBiometricExtractionDraftExceptionAndDiscardDreaft() throws Exception { + MessageDTO messageDTO = new MessageDTO(); + messageDTO.setRid("27847657360002520181210094052"); + messageDTO.setReg_type(RegistrationType.NEW.name()); + messageDTO.setWorkflowInstanceId("123er"); + messageDTO.setIteration(1); + when(idrepoDraftService.idrepoHasDraft(anyString())).thenReturn(true); + IdResponseDTO idResponseDTO=new IdResponseDTO(); + List errorList=new ArrayList<>(); + io.mosip.registration.processor.core.common.rest.dto.ErrorDTO dto=new io.mosip.registration.processor.core.common.rest.dto.ErrorDTO(); + dto.setErrorCode("aa"); + dto.setMessage("bb"); + errorList.add(dto); + idResponseDTO.setId("mosip.id.read"); + idResponseDTO.setResponse(null); + idResponseDTO.setErrors(errorList); + idResponseDTO.setVersion("1.0"); + List segment=new ArrayList<>(); + segment.add(messageDTO.getRid()); + when(registrationProcessorRestClientService.putApi(Mockito.eq(ApiName.IDREPOEXTRACTBIOMETRICS), any(), anyString(), anyString(), Mockito.isNull(), Mockito.eq(IdResponseDTO.class), isNull())).thenReturn(idResponseDTO); + MessageDTO result = biometricExtractionStage.process(messageDTO); + verify(idrepoDraftService,atLeastOnce()).idrepodiscardDraft(anyString()); + + assertTrue(result.getInternalError()); + assertFalse(result.getIsValid()); + } } diff --git a/registration-processor/core-processor/registration-processor-finalization-stage/src/main/java/io/mosip/registration/processor/stages/finalization/stage/FinalizationStage.java b/registration-processor/core-processor/registration-processor-finalization-stage/src/main/java/io/mosip/registration/processor/stages/finalization/stage/FinalizationStage.java index c4236fde362..c1ec34dcf50 100644 --- a/registration-processor/core-processor/registration-processor-finalization-stage/src/main/java/io/mosip/registration/processor/stages/finalization/stage/FinalizationStage.java +++ b/registration-processor/core-processor/registration-processor-finalization-stage/src/main/java/io/mosip/registration/processor/stages/finalization/stage/FinalizationStage.java @@ -1,5 +1,6 @@ package io.mosip.registration.processor.stages.finalization.stage; +import io.mosip.registration.processor.core.common.rest.dto.ErrorDTO; import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -58,6 +59,7 @@ public class FinalizationStage extends MosipVerticleAPIManager{ /** stage properties prefix */ private static final String STAGE_PROPERTY_PREFIX = "mosip.regproc.finalization."; 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; diff --git a/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/code/ApiName.java b/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/code/ApiName.java index bfaaa1ae892..170f9078d6b 100644 --- a/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/code/ApiName.java +++ b/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/code/ApiName.java @@ -197,6 +197,7 @@ public enum ApiName { IDREPOUPDATEDRAFT, IDREPOPUBLISHDRAFT, IDREPOEXTRACTBIOMETRICS, + IDREPODISCARDDREFT, CREDENTIALREQUESTV2; } diff --git a/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/spi/restclient/RegistrationProcessorRestClientService.java b/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/spi/restclient/RegistrationProcessorRestClientService.java index 3db41c9bedb..b2b0019d1f3 100644 --- a/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/spi/restclient/RegistrationProcessorRestClientService.java +++ b/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/spi/restclient/RegistrationProcessorRestClientService.java @@ -187,4 +187,7 @@ public T postApi(String url, MediaType mediaType, List pathsegments, Lis T requestedData, Class responseType) throws ApisResourceAccessException; public Integer headApi(ApiName apiName, List pathsegments, List queryParamName, List queryParamValue) throws ApisResourceAccessException; -} + + public T deleteApi(ApiName apiName, List pathsegments, String queryParam, String queryParamValue, + Class responseType) throws ApisResourceAccessException; + } diff --git a/registration-processor/registration-processor-packet-manager/src/main/java/io/mosip/registration/processor/packet/manager/idreposervice/IdrepoDraftService.java b/registration-processor/registration-processor-packet-manager/src/main/java/io/mosip/registration/processor/packet/manager/idreposervice/IdrepoDraftService.java index 062b0b0640f..8062a3dbc6a 100644 --- a/registration-processor/registration-processor-packet-manager/src/main/java/io/mosip/registration/processor/packet/manager/idreposervice/IdrepoDraftService.java +++ b/registration-processor/registration-processor-packet-manager/src/main/java/io/mosip/registration/processor/packet/manager/idreposervice/IdrepoDraftService.java @@ -33,12 +33,14 @@ public class IdrepoDraftService { private static final Integer IDREPO_DRAFT_FOUND = 200; private static final Integer IDREPO_DRAFT_NOT_FOUND = 204; private static Logger regProcLogger = RegProcessorLogger.getLogger(IdrepoDraftService.class); - private static final String ID_REPO_KEY_MANAGER_ERROR = "IDR-IDS-003"; + private static final String ID_REPO_KEY_MANAGER_ERROR = "IDR-IDS-003"; @Autowired private ObjectMapper mapper; - /** The registration processor rest client service. */ + /** + * The registration processor rest client service. + */ @Autowired private RegistrationProcessorRestClientService registrationProcessorRestClientService; @@ -62,24 +64,32 @@ public ResponseDTO idrepoGetDraft(String id) throws ApisResourceAccessException regProcLogger.debug("idrepoGetDraft entry " + id); IdResponseDTO idResponseDTO = (IdResponseDTO) registrationProcessorRestClientService.getApi( ApiName.IDREPOGETDRAFT, Lists.newArrayList(id), Lists.emptyList(), null, IdResponseDTO.class); + if (idResponseDTO.getErrors() != null && !idResponseDTO.getErrors().isEmpty()) { + ErrorDTO error = idResponseDTO.getErrors().get(0); + regProcLogger.error("Error occured while getting draft for id : " + id, error.toString()); + } + regProcLogger.debug("idrepoGetDraft exit " + id); + return idResponseDTO.getResponse(); + } - regProcLogger.debug("idrepoGetDraft exit " + id); - return idResponseDTO.getResponse(); - } - public boolean idrepoCreateDraft(String id, String uin) throws ApisResourceAccessException { + public boolean idrepoCreateDraft(String id, String uin) throws ApisResourceAccessException, IdrepoDraftException { regProcLogger.debug("idrepoCreateDraft entry " + id); String queryParam = uin != null ? UIN : null; String queryParamValue = uin != null ? uin : null; ResponseWrapper response = (ResponseWrapper) registrationProcessorRestClientService.postApi( ApiName.IDREPOCREATEDRAFT, Lists.newArrayList(id), queryParam, queryParamValue, null, ResponseWrapper.class); - - return (response.getErrors() == null || response.getErrors().isEmpty()); + if (response.getErrors() != null && !response.getErrors().isEmpty()) + { + regProcLogger.error("Error while creating draft for id " + id); + throw new IdrepoDraftException(PlatformErrorMessages.IDREPO_DRAFT_EXCEPTION.getCode(), PlatformErrorMessages.IDREPO_DRAFT_EXCEPTION.getMessage()); + } + return (response.getErrors() == null || response.getErrors().isEmpty()); } - public IdResponseDTO idrepoUpdateDraft(String id, String uin, IdRequestDto idRequestDto) - throws ApisResourceAccessException, IdrepoDraftException, IOException, IdrepoDraftReprocessableException { + public IdResponseDTO idrepoUpdateDraft(String id, String uin, IdRequestDto idRequestDto) + throws ApisResourceAccessException, IdrepoDraftException, IOException, IdrepoDraftReprocessableException { regProcLogger.debug("idrepoUpdateDraft entry " + id); if (!idrepoHasDraft(id)) { regProcLogger.info("Existing draft not found for id " + id + ". Creating new draft."); @@ -98,44 +108,64 @@ public IdResponseDTO idrepoUpdateDraft(String id, String uin, IdRequestDto idReq requestDto.setStatus(responseDTO.getStatus()); requestDto.setUin(responseDTO.getUin()); idRequestDto.setRequest(requestDto); - } - - IdResponseDTO response = (IdResponseDTO) registrationProcessorRestClientService.patchApi( - ApiName.IDREPOUPDATEDRAFT, Lists.newArrayList(id), null, null, idRequestDto, IdResponseDTO.class); - if (response.getErrors() != null && !response.getErrors().isEmpty()) { - ErrorDTO error = response.getErrors().get(0); - regProcLogger.error("Error occured while updating draft for id : " + id, 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()); - } + IdResponseDTO response = new IdResponseDTO(); + response = (IdResponseDTO) registrationProcessorRestClientService.patchApi( + ApiName.IDREPOUPDATEDRAFT, Lists.newArrayList(id), null, null, idRequestDto, IdResponseDTO.class); + if (response.getErrors() != null && !response.getErrors().isEmpty()) { + regProcLogger.info("Error while updating the drant " + id); + idrepodiscardDraft(id); + ErrorDTO error = response.getErrors().get(0); + regProcLogger.error("Error occured while updating draft for id : " + id, error.toString()); + if (response.getErrors().get(0).getErrorCode().equalsIgnoreCase(ID_REPO_KEY_MANAGER_ERROR)) { + regProcLogger.error("Error occured Deleting the Draft : " + id, error.toString()); + throw new IdrepoDraftReprocessableException(error.getErrorCode(), error.getMessage()); + } else { + throw new IdrepoDraftException(error.getErrorCode(), error.getMessage()); + } } - regProcLogger.debug("idrepoUpdateDraft exit " + id); return response; } - - public IdResponseDTO idrepoPublishDraft(String id) - throws ApisResourceAccessException, IdrepoDraftException, IdrepoDraftReprocessableException { - regProcLogger.debug("idrepoPublishDraft entry " + id); - List pathsegments=new ArrayList(); - pathsegments.add(id); - IdResponseDTO response = (IdResponseDTO) registrationProcessorRestClientService. - getApi(ApiName.IDREPOPUBLISHDRAFT, pathsegments, "", "", IdResponseDTO.class); - if (response.getErrors() != null && !response.getErrors().isEmpty()) { - ErrorDTO error = response.getErrors().get(0); - regProcLogger.error("Error occured while updating draft for id : " + id, 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()); - } + public IdResponseDTO idrepoPublishDraft(String id) + throws ApisResourceAccessException, IdrepoDraftException, IdrepoDraftReprocessableException { + regProcLogger.debug("idrepoPublishDraft entry " + id); + List pathsegments = new ArrayList(); + pathsegments.add(id); + IdResponseDTO response = (IdResponseDTO) registrationProcessorRestClientService. + getApi(ApiName.IDREPOPUBLISHDRAFT, pathsegments, "", "", IdResponseDTO.class); + + if(response.getErrors()!=null && !response.getErrors().isEmpty()) + { + ErrorDTO error=response.getErrors().get(0); + regProcLogger.error("Error occured while publishing the Draft : " + id, error.toString()); + idrepodiscardDraft(id); + 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()); + } } - regProcLogger.debug("idrepoPublishDraft exit " + id); return response; - } + } + + public Boolean idrepodiscardDraft(String id) throws ApisResourceAccessException, IdrepoDraftReprocessableException, IdrepoDraftException { + regProcLogger.debug("idrepoDiscardDraft entry " + id); + List pathsegments = new ArrayList(); + pathsegments.add(id); + IdResponseDTO response = (IdResponseDTO) registrationProcessorRestClientService. + deleteApi(ApiName.IDREPODISCARDDREFT, pathsegments, "", "", IdResponseDTO.class); + if (response.getErrors() != null && !response.getErrors().isEmpty()) { + ErrorDTO error = response.getErrors().get(0); + regProcLogger.error("Error occured while discarding draft for id : " + id, 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 true; + } } diff --git a/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java b/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java index 580e2b3c17d..4fe26dadc92 100644 --- a/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java +++ b/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java @@ -3,7 +3,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import java.io.IOException; @@ -15,6 +15,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @@ -101,6 +102,7 @@ public void idrepoDraftCheckExceptionTest() throws ApisResourceAccessException, when(registrationProcessorRestClientService.headApi (ApiName.IDREPOHASDRAFT, Lists.newArrayList(ID), null, null)).thenReturn(500); + idrepoDraftService.idrepoHasDraft(ID); } @@ -142,8 +144,23 @@ public void idrepoPublishDraftExceptionTest() idResponseDTO1.setErrors(Lists.newArrayList(errorDTO)); when(registrationProcessorRestClientService.getApi( ApiName.IDREPOPUBLISHDRAFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(idResponseDTO1); + ResponseDTO discardresponseDTO = new ResponseDTO(); + discardresponseDTO.setStatus("Drafted"); + discardresponseDTO.setRegistrationId(ID); + + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("UIN", "1234"); + discardresponseDTO.setIdentity(jsonObject1); + IdResponseDTO discardIdresponceDto=new IdResponseDTO(); + discardIdresponceDto = new IdResponseDTO(); + discardIdresponceDto.setErrors(null); + discardIdresponceDto.setId("id.uin.update"); + discardIdresponceDto.setResponse(discardresponseDTO); + when(registrationProcessorRestClientService. + deleteApi(ApiName.IDREPODISCARDDREFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponceDto); idrepoDraftService.idrepoPublishDraft(ID); + Mockito.verify(idrepoDraftService.idrepodiscardDraft(any()),times(1)); } @Test @@ -154,7 +171,6 @@ public void idrepoCreateDraftSuccessTest() throws ApisResourceAccessException, I ApiName.IDREPOCREATEDRAFT, Lists.newArrayList(ID), null, null, null, ResponseWrapper.class)).thenReturn(responseWrapper); boolean result = idrepoDraftService.idrepoCreateDraft(ID, null); - assertTrue(result); } @@ -199,7 +215,24 @@ public void idrepoUpdateDraftExceptionTest() when(registrationProcessorRestClientService.patchApi( any(), any(), any(), any(), any(), any())).thenReturn(idResponseDTO1); - idrepoDraftService.idrepoUpdateDraft(ID, null, idRequestDto); + ResponseDTO discardresponseDTO = new ResponseDTO(); + discardresponseDTO.setStatus("Drafted"); + discardresponseDTO.setRegistrationId(ID); + + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("UIN", "1234"); + discardresponseDTO.setIdentity(jsonObject1); + IdResponseDTO discardIdresponceDto=new IdResponseDTO(); + discardIdresponceDto = new IdResponseDTO(); + discardIdresponceDto.setErrors(null); + discardIdresponceDto.setId("id.uin.update"); + discardIdresponceDto.setResponse(discardresponseDTO); + when(registrationProcessorRestClientService. + deleteApi(ApiName.IDREPODISCARDDREFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponceDto); + + + IdResponseDTO idResponseDTO2=idrepoDraftService.idrepoUpdateDraft(ID, null, idRequestDto); + verify(idrepoDraftService.idrepodiscardDraft(any()),times(1)); } @@ -223,9 +256,43 @@ public void idrepoDraftReprocessableExceptionTest() Lists.emptyList(), null, IdResponseDTO.class)).thenReturn(idResponseDTO); when(registrationProcessorRestClientService.patchApi(any(), any(), any(), any(), any(), any())) .thenReturn(idResponseDTO1); + ResponseDTO discardresponseDTO = new ResponseDTO(); + discardresponseDTO.setStatus("Drafted"); + discardresponseDTO.setRegistrationId(ID); + + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("UIN", "1234"); + discardresponseDTO.setIdentity(jsonObject1); + IdResponseDTO discardIdresponceDto=new IdResponseDTO(); + discardIdresponceDto = new IdResponseDTO(); + discardIdresponceDto.setErrors(null); + discardIdresponceDto.setId("id.uin.update"); + discardIdresponceDto.setResponse(discardresponseDTO); + when(registrationProcessorRestClientService. + deleteApi(ApiName.IDREPODISCARDDREFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponceDto); idrepoDraftService.idrepoUpdateDraft(ID, null, idRequestDto); + Mockito.verify(idrepoDraftService.idrepodiscardDraft(any()),times(1)); } - + @Test + public void discardDraftSuccessTest() throws IdrepoDraftReprocessableException, IdrepoDraftException, ApisResourceAccessException { + ResponseDTO discardresponseDTO = new ResponseDTO(); + discardresponseDTO.setStatus("Drafted"); + discardresponseDTO.setRegistrationId(ID); + + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("UIN", "1234"); + discardresponseDTO.setIdentity(jsonObject1); + IdResponseDTO discardIdresponceDto=new IdResponseDTO(); + discardIdresponceDto = new IdResponseDTO(); + discardIdresponceDto.setErrors(null); + discardIdresponceDto.setId("id.uin.update"); + discardIdresponceDto.setResponse(discardresponseDTO); + when(registrationProcessorRestClientService. + deleteApi(ApiName.IDREPODISCARDDREFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponceDto); + + Boolean result= idrepoDraftService.idrepodiscardDraft(ID); + assertTrue(result); + } } diff --git a/registration-processor/registration-processor-rest-client/src/main/java/io/mosip/registration/processor/rest/client/service/impl/RegistrationProcessorRestClientServiceImpl.java b/registration-processor/registration-processor-rest-client/src/main/java/io/mosip/registration/processor/rest/client/service/impl/RegistrationProcessorRestClientServiceImpl.java index 81681958f63..8fa682884f1 100644 --- a/registration-processor/registration-processor-rest-client/src/main/java/io/mosip/registration/processor/rest/client/service/impl/RegistrationProcessorRestClientServiceImpl.java +++ b/registration-processor/registration-processor-rest-client/src/main/java/io/mosip/registration/processor/rest/client/service/impl/RegistrationProcessorRestClientServiceImpl.java @@ -521,4 +521,58 @@ public Integer headApi(ApiName apiName, List pathsegments, List return obj; } + + @Override + public Object deleteApi(ApiName apiName, List pathsegments, String queryParamName, String queryParamValue, + Class responseType) throws ApisResourceAccessException { + regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), "", + "RegistrationProcessorRestClientServiceImpl::deleteApi()::entry"); + Object obj = null; + String apiHostIpPort = env.getProperty(apiName.name()); + + UriComponentsBuilder builder = null; + UriComponents uriComponents = null; + if (apiHostIpPort != null) { + + builder = UriComponentsBuilder.fromUriString(apiHostIpPort); + if (!((pathsegments == null) || (pathsegments.isEmpty()))) { + for (String segment : pathsegments) { + if (!((segment == null) || (("").equals(segment)))) { + builder.pathSegment(segment); + } + } + + } + + if (!((queryParamName == null) || (("").equals(queryParamName)))) { + + String[] queryParamNameArr = queryParamName.split(","); + String[] queryParamValueArr = queryParamValue.split(","); + for (int i = 0; i < queryParamNameArr.length; i++) { + builder.queryParam(queryParamNameArr[i], queryParamValueArr[i]); + } + + } + + try { + + uriComponents = builder.build(false).encode(); + regProcLogger.debug(uriComponents.toUri().toString(), "URI", "", ""); + obj = restApiClient.deleteApi(uriComponents.toUri(), responseType); + + } catch (Exception e) { + regProcLogger.error(LoggerFileConstant.SESSIONID.toString(), + LoggerFileConstant.REGISTRATIONID.toString(), "", + e.getMessage() + ExceptionUtils.getStackTrace(e)); + + throw new ApisResourceAccessException( + PlatformErrorMessages.RPR_RCT_UNKNOWN_RESOURCE_EXCEPTION.getCode(), e); + + } + } + regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(), "", + "RegistrationProcessorRestClientServiceImpl::deleteApi::exit"); + return obj; + } + } \ No newline at end of file diff --git a/registration-processor/registration-processor-rest-client/src/main/java/io/mosip/registration/processor/rest/client/utils/RestApiClient.java b/registration-processor/registration-processor-rest-client/src/main/java/io/mosip/registration/processor/rest/client/utils/RestApiClient.java index 419c533200f..3565023f627 100644 --- a/registration-processor/registration-processor-rest-client/src/main/java/io/mosip/registration/processor/rest/client/utils/RestApiClient.java +++ b/registration-processor/registration-processor-rest-client/src/main/java/io/mosip/registration/processor/rest/client/utils/RestApiClient.java @@ -313,4 +313,21 @@ public void tokenExceptionHandler(Exception e) { } } + + public T deleteApi(URI uri, Class responseType) throws Exception { + T result = null; + + try { + result = (T) localRestTemplate.exchange(uri, HttpMethod.DELETE, setRequestHeader(null, null), responseType) + .getBody(); + } catch (Exception e) { + logger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.APPLICATIONID.toString(), + LoggerFileConstant.APPLICATIONID.toString(), e.getMessage() + ExceptionUtils.getStackTrace(e)); + tokenExceptionHandler(e); + throw e; + } + return result; + } + + } diff --git a/registration-processor/registration-processor-rest-client/src/test/java/io/mosip/registration/processor/rest/client/service/RegistrationProcessorRestClientServiceTest.java b/registration-processor/registration-processor-rest-client/src/test/java/io/mosip/registration/processor/rest/client/service/RegistrationProcessorRestClientServiceTest.java index a4127a1e060..ee3d0932f2f 100644 --- a/registration-processor/registration-processor-rest-client/src/test/java/io/mosip/registration/processor/rest/client/service/RegistrationProcessorRestClientServiceTest.java +++ b/registration-processor/registration-processor-rest-client/src/test/java/io/mosip/registration/processor/rest/client/service/RegistrationProcessorRestClientServiceTest.java @@ -32,11 +32,15 @@ public class RegistrationProcessorRestClientServiceTest { @InjectMocks RegistrationProcessorRestClientService registrationProcessorRestClientService = new RegistrationProcessorRestClientServiceImpl(); - /** The rest api client. */ + /** + * The rest api client. + */ @Mock private RestApiClient restApiClient; - /** The env. */ + /** + * The env. + */ @Mock private Environment env; private AuditResponseDto auditResponseDto; @@ -89,7 +93,7 @@ public void postObjecTestFailureTest() throws Exception { registrationProcessorRestClientService.postApi(ApiName.AUDIT, "query1", "12345", auditRequestDto, AuditResponseDto.class); } - + @Test public void getObjectForArgListSuccessTest() throws Exception { @@ -135,7 +139,7 @@ public void postObjectTestFailureTest() throws Exception { registrationProcessorRestClientService.postApi(ApiName.AUDIT, pathSegments, "query1", "12345", auditRequestDto, AuditResponseDto.class); } - + @Test public void postObjectForArgListSuccessTest() throws Exception { AuditRequestDto auditRequestDto = new AuditRequestDto(); @@ -162,7 +166,7 @@ public void postObjectForArgListTestFailureTest() throws Exception { registrationProcessorRestClientService.postApi(ApiName.AUDIT, null, pathSegments, Arrays.asList("query1"), Arrays.asList("12345"), auditRequestDto, AuditResponseDto.class); } - + @Test public void patchObjectSuccessTest() throws Exception { AuditRequestDto auditRequestDto = new AuditRequestDto(); @@ -175,7 +179,7 @@ public void patchObjectSuccessTest() throws Exception { pathSegments, "query1", "12345", auditRequestDto, AuditResponseDto.class); assertEquals(true, resultDto.isStatus()); } - + @Test(expected = ApisResourceAccessException.class) public void patchObjectTestFailureTest() throws Exception { AuditRequestDto auditRequestDto = new AuditRequestDto(); @@ -188,20 +192,20 @@ public void patchObjectTestFailureTest() throws Exception { registrationProcessorRestClientService.patchApi(ApiName.AUDIT, pathSegments, "query1", "12345", auditRequestDto, AuditResponseDto.class); } - + @Test public void putObjectSuccessTest() throws Exception { AuditRequestDto auditRequestDto = new AuditRequestDto(); Mockito.when(env.getProperty(ArgumentMatchers.any())).thenReturn("AUDIT"); - Mockito.when(restApiClient.putApi(ArgumentMatchers.any(),ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any())) + Mockito.when(restApiClient.putApi(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any())) .thenReturn(auditResponseDto); List pathSegments = new ArrayList<>(); pathSegments.add("test"); AuditResponseDto resultDto = (AuditResponseDto) registrationProcessorRestClientService.putApi(ApiName.AUDIT, - pathSegments, "query1", "12345", auditRequestDto, AuditResponseDto.class,null); + pathSegments, "query1", "12345", auditRequestDto, AuditResponseDto.class, null); assertEquals(true, resultDto.isStatus()); } - + @Test(expected = ApisResourceAccessException.class) public void putObjectTestFailureTest() throws Exception { AuditRequestDto auditRequestDto = new AuditRequestDto(); @@ -212,9 +216,9 @@ public void putObjectTestFailureTest() throws Exception { Mockito.when(restApiClient.putApi(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any())) .thenThrow(exp); registrationProcessorRestClientService.putApi(ApiName.AUDIT, pathSegments, "query1", "12345", auditRequestDto, - AuditResponseDto.class,null); + AuditResponseDto.class, null); } - + @Test public void postObjectForUrlSuccessTest() throws Exception { AuditRequestDto auditRequestDto = new AuditRequestDto(); @@ -261,4 +265,23 @@ public void headObjectTestFailureTest() throws Exception { registrationProcessorRestClientService.headApi(ApiName.AUDIT, pathSegments, Arrays.asList("query1"), Arrays.asList("12345")); } + + @Test + public void deleteObjecSuccessTest() throws Exception { + + Mockito.when(env.getProperty(ArgumentMatchers.any())).thenReturn("AUDIT"); + Mockito.when(restApiClient.deleteApi(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(auditResponseDto); + AuditResponseDto resultDto = (AuditResponseDto) registrationProcessorRestClientService.deleteApi(ApiName.AUDIT, + null, "query1", "12345", AuditResponseDto.class); + assertEquals(true, resultDto.isStatus()); + } + + @Test(expected = ApisResourceAccessException.class) + public void deleteObjecTestFailureTest() throws Exception { + Mockito.when(env.getProperty(ArgumentMatchers.any())).thenReturn("AUDIT"); + ResourceAccessException exp = new ResourceAccessException("errorMessage"); + Mockito.when(restApiClient.deleteApi(ArgumentMatchers.any(), ArgumentMatchers.any())).thenThrow(exp); + + registrationProcessorRestClientService.deleteApi(ApiName.AUDIT, Arrays.asList("abc", "def"), "query1", "12345", + AuditResponseDto.class); } } From 3c5ddc32468f899fa8500dae76aa145c1643ea2a Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Tue, 5 Mar 2024 15:28:08 +0530 Subject: [PATCH 2/6] [Mosip-31365] fixing PR comments Signed-off-by: khuddus shariff --- .../stage/BiometricExtractionStage.java | 2 +- .../finalization/stage/FinalizationStage.java | 1 - .../processor/core/code/ApiName.java | 2 +- .../idreposervice/IdrepoDraftService.java | 8 +++--- .../impl/test/IdrepoDraftServiceTest.java | 28 ++++++++----------- 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/main/java/io/mosip/registration/processor/stages/biometric/extraction/stage/BiometricExtractionStage.java b/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/main/java/io/mosip/registration/processor/stages/biometric/extraction/stage/BiometricExtractionStage.java index 8291d679b35..80e050a7eae 100644 --- a/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/main/java/io/mosip/registration/processor/stages/biometric/extraction/stage/BiometricExtractionStage.java +++ b/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/main/java/io/mosip/registration/processor/stages/biometric/extraction/stage/BiometricExtractionStage.java @@ -382,7 +382,7 @@ private IdResponseDTO addBiometricExtractiontoIdRepository(ExtractorDto dto, * @throws JsonParseException * @throws RegistrationProcessorCheckedException */ - private ExtractorsDto getExtractors(String id) throws JSONException, ApisResourceAccessException, JsonParseException, JsonMappingException, JsonProcessingException, IOException, RegistrationProcessorCheckedException, IdrepoDraftReprocessableException, IdrepoDraftException { + private ExtractorsDto getExtractors(String id) throws JSONException, ApisResourceAccessException, JsonParseException, JsonMappingException, JsonProcessingException, IOException, RegistrationProcessorCheckedException { JSONArray jArray=new JSONArray(partnerPolicyIdsJson); ExtractorsDto extractorsDto=new ExtractorsDto(); List errors = new ArrayList<>(); diff --git a/registration-processor/core-processor/registration-processor-finalization-stage/src/main/java/io/mosip/registration/processor/stages/finalization/stage/FinalizationStage.java b/registration-processor/core-processor/registration-processor-finalization-stage/src/main/java/io/mosip/registration/processor/stages/finalization/stage/FinalizationStage.java index c1ec34dcf50..e01b00bf9bc 100644 --- a/registration-processor/core-processor/registration-processor-finalization-stage/src/main/java/io/mosip/registration/processor/stages/finalization/stage/FinalizationStage.java +++ b/registration-processor/core-processor/registration-processor-finalization-stage/src/main/java/io/mosip/registration/processor/stages/finalization/stage/FinalizationStage.java @@ -59,7 +59,6 @@ public class FinalizationStage extends MosipVerticleAPIManager{ /** stage properties prefix */ private static final String STAGE_PROPERTY_PREFIX = "mosip.regproc.finalization."; 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; diff --git a/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/code/ApiName.java b/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/code/ApiName.java index 170f9078d6b..61fef27c7dc 100644 --- a/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/code/ApiName.java +++ b/registration-processor/registration-processor-core/src/main/java/io/mosip/registration/processor/core/code/ApiName.java @@ -197,7 +197,7 @@ public enum ApiName { IDREPOUPDATEDRAFT, IDREPOPUBLISHDRAFT, IDREPOEXTRACTBIOMETRICS, - IDREPODISCARDDREFT, + IDREPODISCARDDRAFT, CREDENTIALREQUESTV2; } diff --git a/registration-processor/registration-processor-packet-manager/src/main/java/io/mosip/registration/processor/packet/manager/idreposervice/IdrepoDraftService.java b/registration-processor/registration-processor-packet-manager/src/main/java/io/mosip/registration/processor/packet/manager/idreposervice/IdrepoDraftService.java index 8062a3dbc6a..4b69ee65e3c 100644 --- a/registration-processor/registration-processor-packet-manager/src/main/java/io/mosip/registration/processor/packet/manager/idreposervice/IdrepoDraftService.java +++ b/registration-processor/registration-processor-packet-manager/src/main/java/io/mosip/registration/processor/packet/manager/idreposervice/IdrepoDraftService.java @@ -60,13 +60,14 @@ public boolean idrepoHasDraft(String id) throws ApisResourceAccessException, Idr return hasDraft; } - public ResponseDTO idrepoGetDraft(String id) throws ApisResourceAccessException { + public ResponseDTO idrepoGetDraft(String id) throws ApisResourceAccessException, IdrepoDraftException { regProcLogger.debug("idrepoGetDraft entry " + id); IdResponseDTO idResponseDTO = (IdResponseDTO) registrationProcessorRestClientService.getApi( ApiName.IDREPOGETDRAFT, Lists.newArrayList(id), Lists.emptyList(), null, IdResponseDTO.class); if (idResponseDTO.getErrors() != null && !idResponseDTO.getErrors().isEmpty()) { ErrorDTO error = idResponseDTO.getErrors().get(0); regProcLogger.error("Error occured while getting draft for id : " + id, error.toString()); + throw new IdrepoDraftException(error.getErrorCode(), error.getMessage()); } regProcLogger.debug("idrepoGetDraft exit " + id); return idResponseDTO.getResponse(); @@ -109,8 +110,7 @@ public IdResponseDTO idrepoUpdateDraft(String id, String uin, IdRequestDto idReq requestDto.setUin(responseDTO.getUin()); idRequestDto.setRequest(requestDto); } - IdResponseDTO response = new IdResponseDTO(); - response = (IdResponseDTO) registrationProcessorRestClientService.patchApi( + IdResponseDTO response = (IdResponseDTO) registrationProcessorRestClientService.patchApi( ApiName.IDREPOUPDATEDRAFT, Lists.newArrayList(id), null, null, idRequestDto, IdResponseDTO.class); if (response.getErrors() != null && !response.getErrors().isEmpty()) { regProcLogger.info("Error while updating the drant " + id); @@ -156,7 +156,7 @@ public Boolean idrepodiscardDraft(String id) throws ApisResourceAccessException, List pathsegments = new ArrayList(); pathsegments.add(id); IdResponseDTO response = (IdResponseDTO) registrationProcessorRestClientService. - deleteApi(ApiName.IDREPODISCARDDREFT, pathsegments, "", "", IdResponseDTO.class); + deleteApi(ApiName.IDREPODISCARDDRAFT, pathsegments, "", "", IdResponseDTO.class); if (response.getErrors() != null && !response.getErrors().isEmpty()) { ErrorDTO error = response.getErrors().get(0); regProcLogger.error("Error occured while discarding draft for id : " + id, error.toString()); diff --git a/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java b/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java index 4fe26dadc92..59edb5e519b 100644 --- a/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java +++ b/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java @@ -157,7 +157,7 @@ public void idrepoPublishDraftExceptionTest() discardIdresponceDto.setId("id.uin.update"); discardIdresponceDto.setResponse(discardresponseDTO); when(registrationProcessorRestClientService. - deleteApi(ApiName.IDREPODISCARDDREFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponceDto); + deleteApi(ApiName.IDREPODISCARDDRAFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponceDto); idrepoDraftService.idrepoPublishDraft(ID); Mockito.verify(idrepoDraftService.idrepodiscardDraft(any()),times(1)); @@ -228,7 +228,7 @@ public void idrepoUpdateDraftExceptionTest() discardIdresponceDto.setId("id.uin.update"); discardIdresponceDto.setResponse(discardresponseDTO); when(registrationProcessorRestClientService. - deleteApi(ApiName.IDREPODISCARDDREFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponceDto); + deleteApi(ApiName.IDREPODISCARDDRAFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponceDto); IdResponseDTO idResponseDTO2=idrepoDraftService.idrepoUpdateDraft(ID, null, idRequestDto); @@ -257,19 +257,16 @@ public void idrepoDraftReprocessableExceptionTest() when(registrationProcessorRestClientService.patchApi(any(), any(), any(), any(), any(), any())) .thenReturn(idResponseDTO1); ResponseDTO discardresponseDTO = new ResponseDTO(); - discardresponseDTO.setStatus("Drafted"); discardresponseDTO.setRegistrationId(ID); - JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("UIN", "1234"); discardresponseDTO.setIdentity(jsonObject1); - IdResponseDTO discardIdresponceDto=new IdResponseDTO(); - discardIdresponceDto = new IdResponseDTO(); - discardIdresponceDto.setErrors(null); - discardIdresponceDto.setId("id.uin.update"); - discardIdresponceDto.setResponse(discardresponseDTO); + IdResponseDTO discardIdresponseDto= new IdResponseDTO(); + discardIdresponseDto.setErrors(null); + discardIdresponseDto.setId("id.uin.update"); + discardIdresponseDto.setResponse(discardresponseDTO); when(registrationProcessorRestClientService. - deleteApi(ApiName.IDREPODISCARDDREFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponceDto); + deleteApi(ApiName.IDREPODISCARDDRAFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponseDto); idrepoDraftService.idrepoUpdateDraft(ID, null, idRequestDto); Mockito.verify(idrepoDraftService.idrepodiscardDraft(any()),times(1)); @@ -284,13 +281,12 @@ public void discardDraftSuccessTest() throws IdrepoDraftReprocessableException, JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("UIN", "1234"); discardresponseDTO.setIdentity(jsonObject1); - IdResponseDTO discardIdresponceDto=new IdResponseDTO(); - discardIdresponceDto = new IdResponseDTO(); - discardIdresponceDto.setErrors(null); - discardIdresponceDto.setId("id.uin.update"); - discardIdresponceDto.setResponse(discardresponseDTO); + IdResponseDTO discardIdresponseDto= new IdResponseDTO(); + discardIdresponseDto.setErrors(null); + discardIdresponseDto.setId("id.uin.update"); + discardIdresponseDto.setResponse(discardresponseDTO); when(registrationProcessorRestClientService. - deleteApi(ApiName.IDREPODISCARDDREFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponceDto); + deleteApi(ApiName.IDREPODISCARDDRAFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponseDto); Boolean result= idrepoDraftService.idrepodiscardDraft(ID); assertTrue(result); From c82e10b3a0de5a9fb55e40680d2cbcf7db3bdef4 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Thu, 7 Mar 2024 16:03:32 +0530 Subject: [PATCH 3/6] [Mosip_31365] setting identity to idrequstDTO Signed-off-by: khuddus shariff --- .../packet/manager/idreposervice/IdrepoDraftService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/registration-processor/registration-processor-packet-manager/src/main/java/io/mosip/registration/processor/packet/manager/idreposervice/IdrepoDraftService.java b/registration-processor/registration-processor-packet-manager/src/main/java/io/mosip/registration/processor/packet/manager/idreposervice/IdrepoDraftService.java index 4b69ee65e3c..b366d6d85d2 100644 --- a/registration-processor/registration-processor-packet-manager/src/main/java/io/mosip/registration/processor/packet/manager/idreposervice/IdrepoDraftService.java +++ b/registration-processor/registration-processor-packet-manager/src/main/java/io/mosip/registration/processor/packet/manager/idreposervice/IdrepoDraftService.java @@ -104,7 +104,8 @@ public IdResponseDTO idrepoUpdateDraft(String id, String uin, IdRequestDto idReq JSONObject existingIdentity = mapper.readValue(mapper.writeValueAsString(responseDTO.getIdentity()), JSONObject.class); JSONObject newIdentity = mapper.readValue(mapper.writeValueAsString(idRequestDto.getRequest().getIdentity()), JSONObject.class); newIdentity.put(UIN, existingIdentity.get(UIN)); - idRequestDto.getRequest().setIdentity(newIdentity); +// setting the identity to request while updating the draft. + requestDto.setIdentity(newIdentity); requestDto.setRegistrationId(responseDTO.getRegistrationId()); requestDto.setStatus(responseDTO.getStatus()); requestDto.setUin(responseDTO.getUin()); From 110561f533fc55c50f66c309866ca2d7c28d60ca Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Thu, 7 Mar 2024 17:32:19 +0530 Subject: [PATCH 4/6] spell check Signed-off-by: khuddus shariff --- .../service/impl/test/IdrepoDraftServiceTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java b/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java index 59edb5e519b..596db0a56fd 100644 --- a/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java +++ b/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java @@ -151,13 +151,13 @@ public void idrepoPublishDraftExceptionTest() JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("UIN", "1234"); discardresponseDTO.setIdentity(jsonObject1); - IdResponseDTO discardIdresponceDto=new IdResponseDTO(); - discardIdresponceDto = new IdResponseDTO(); - discardIdresponceDto.setErrors(null); - discardIdresponceDto.setId("id.uin.update"); - discardIdresponceDto.setResponse(discardresponseDTO); + IdResponseDTO discardIdresponseDto=new IdResponseDTO(); + discardIdresponseDto = new IdResponseDTO(); + discardIdresponseDto.setErrors(null); + discardIdresponseDto.setId("id.uin.update"); + discardIdresponseDto.setResponse(discardresponseDTO); when(registrationProcessorRestClientService. - deleteApi(ApiName.IDREPODISCARDDRAFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponceDto); + deleteApi(ApiName.IDREPODISCARDDRAFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponseDto); idrepoDraftService.idrepoPublishDraft(ID); Mockito.verify(idrepoDraftService.idrepodiscardDraft(any()),times(1)); From de24cdfb301baacc035f1fdb05946b10e444e030 Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Thu, 7 Mar 2024 17:43:14 +0530 Subject: [PATCH 5/6] spell check Signed-off-by: khuddus shariff --- .../service/impl/test/IdrepoDraftServiceTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java b/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java index 596db0a56fd..fe6dab9cc6f 100644 --- a/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java +++ b/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java @@ -222,13 +222,13 @@ public void idrepoUpdateDraftExceptionTest() JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("UIN", "1234"); discardresponseDTO.setIdentity(jsonObject1); - IdResponseDTO discardIdresponceDto=new IdResponseDTO(); - discardIdresponceDto = new IdResponseDTO(); - discardIdresponceDto.setErrors(null); - discardIdresponceDto.setId("id.uin.update"); - discardIdresponceDto.setResponse(discardresponseDTO); + IdResponseDTO discardIdresponseDto=new IdResponseDTO(); + discardIdresponseDto = new IdResponseDTO(); + discardIdresponseDto.setErrors(null); + discardIdresponseDto.setId("id.uin.update"); + discardIdresponseDto.setResponse(discardresponseDTO); when(registrationProcessorRestClientService. - deleteApi(ApiName.IDREPODISCARDDRAFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponceDto); + deleteApi(ApiName.IDREPODISCARDDRAFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponseDto); IdResponseDTO idResponseDTO2=idrepoDraftService.idrepoUpdateDraft(ID, null, idRequestDto); From 4b5e81c6af488ee378702b9f7a9f2502fea9784b Mon Sep 17 00:00:00 2001 From: khuddus shariff Date: Wed, 13 Mar 2024 16:48:22 +0530 Subject: [PATCH 6/6] [Mosip_31365] calling discaedDraft api only when we get the non reprocessable exception Signed-off-by: khuddus shariff --- .../extraction/stage/BiometricExtractionStage.java | 2 +- .../stages/test/BiometricExtractionStageTest.java | 2 +- .../packet/manager/idreposervice/IdrepoDraftService.java | 6 +++--- .../manager/service/impl/test/IdrepoDraftServiceTest.java | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/main/java/io/mosip/registration/processor/stages/biometric/extraction/stage/BiometricExtractionStage.java b/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/main/java/io/mosip/registration/processor/stages/biometric/extraction/stage/BiometricExtractionStage.java index 80e050a7eae..2f7651b3ab4 100644 --- a/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/main/java/io/mosip/registration/processor/stages/biometric/extraction/stage/BiometricExtractionStage.java +++ b/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/main/java/io/mosip/registration/processor/stages/biometric/extraction/stage/BiometricExtractionStage.java @@ -359,12 +359,12 @@ private IdResponseDTO addBiometricExtractiontoIdRepository(ExtractorDto dto, List 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()) { - idrepoDraftService.idrepodiscardDraft(registrationId); 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 { + idrepoDraftService.idrepoDiscardDraft(registrationId); throw new IdrepoDraftException(error.getErrorCode(), error.getMessage()); } } diff --git a/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/test/java/io/mosip/registration/processor/stages/biometric/extraction/stages/test/BiometricExtractionStageTest.java b/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/test/java/io/mosip/registration/processor/stages/biometric/extraction/stages/test/BiometricExtractionStageTest.java index 4f3f604eacc..cadca1ffe62 100644 --- a/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/test/java/io/mosip/registration/processor/stages/biometric/extraction/stages/test/BiometricExtractionStageTest.java +++ b/registration-processor/core-processor/registration-processor-biometric-extraction-stage/src/test/java/io/mosip/registration/processor/stages/biometric/extraction/stages/test/BiometricExtractionStageTest.java @@ -378,7 +378,7 @@ public void testBiometricExtractionDraftExceptionAndDiscardDreaft() throws Excep segment.add(messageDTO.getRid()); when(registrationProcessorRestClientService.putApi(Mockito.eq(ApiName.IDREPOEXTRACTBIOMETRICS), any(), anyString(), anyString(), Mockito.isNull(), Mockito.eq(IdResponseDTO.class), isNull())).thenReturn(idResponseDTO); MessageDTO result = biometricExtractionStage.process(messageDTO); - verify(idrepoDraftService,atLeastOnce()).idrepodiscardDraft(anyString()); + verify(idrepoDraftService,atLeastOnce()).idrepoDiscardDraft(anyString()); assertTrue(result.getInternalError()); assertFalse(result.getIsValid()); diff --git a/registration-processor/registration-processor-packet-manager/src/main/java/io/mosip/registration/processor/packet/manager/idreposervice/IdrepoDraftService.java b/registration-processor/registration-processor-packet-manager/src/main/java/io/mosip/registration/processor/packet/manager/idreposervice/IdrepoDraftService.java index b366d6d85d2..d192ecf12bf 100644 --- a/registration-processor/registration-processor-packet-manager/src/main/java/io/mosip/registration/processor/packet/manager/idreposervice/IdrepoDraftService.java +++ b/registration-processor/registration-processor-packet-manager/src/main/java/io/mosip/registration/processor/packet/manager/idreposervice/IdrepoDraftService.java @@ -115,7 +115,7 @@ public IdResponseDTO idrepoUpdateDraft(String id, String uin, IdRequestDto idReq ApiName.IDREPOUPDATEDRAFT, Lists.newArrayList(id), null, null, idRequestDto, IdResponseDTO.class); if (response.getErrors() != null && !response.getErrors().isEmpty()) { regProcLogger.info("Error while updating the drant " + id); - idrepodiscardDraft(id); + idrepoDiscardDraft(id); ErrorDTO error = response.getErrors().get(0); regProcLogger.error("Error occured while updating draft for id : " + id, error.toString()); if (response.getErrors().get(0).getErrorCode().equalsIgnoreCase(ID_REPO_KEY_MANAGER_ERROR)) { @@ -141,10 +141,10 @@ public IdResponseDTO idrepoPublishDraft(String id) { ErrorDTO error=response.getErrors().get(0); regProcLogger.error("Error occured while publishing the Draft : " + id, error.toString()); - idrepodiscardDraft(id); if (response.getErrors().get(0).getErrorCode().equalsIgnoreCase(ID_REPO_KEY_MANAGER_ERROR)) { throw new IdrepoDraftReprocessableException(error.getErrorCode(), error.getMessage()); } else { + idrepoDiscardDraft(id); throw new IdrepoDraftException(error.getErrorCode(), error.getMessage()); } } @@ -152,7 +152,7 @@ public IdResponseDTO idrepoPublishDraft(String id) return response; } - public Boolean idrepodiscardDraft(String id) throws ApisResourceAccessException, IdrepoDraftReprocessableException, IdrepoDraftException { + public Boolean idrepoDiscardDraft(String id) throws ApisResourceAccessException, IdrepoDraftReprocessableException, IdrepoDraftException { regProcLogger.debug("idrepoDiscardDraft entry " + id); List pathsegments = new ArrayList(); pathsegments.add(id); diff --git a/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java b/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java index fe6dab9cc6f..87adaf1902b 100644 --- a/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java +++ b/registration-processor/registration-processor-packet-manager/src/test/java/io/mosip/registration/processor/packet/manager/service/impl/test/IdrepoDraftServiceTest.java @@ -160,7 +160,7 @@ public void idrepoPublishDraftExceptionTest() deleteApi(ApiName.IDREPODISCARDDRAFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponseDto); idrepoDraftService.idrepoPublishDraft(ID); - Mockito.verify(idrepoDraftService.idrepodiscardDraft(any()),times(1)); + Mockito.verify(idrepoDraftService.idrepoDiscardDraft(any()),times(1)); } @Test @@ -232,7 +232,7 @@ public void idrepoUpdateDraftExceptionTest() IdResponseDTO idResponseDTO2=idrepoDraftService.idrepoUpdateDraft(ID, null, idRequestDto); - verify(idrepoDraftService.idrepodiscardDraft(any()),times(1)); + verify(idrepoDraftService.idrepoDiscardDraft(any()),times(1)); } @@ -269,7 +269,7 @@ public void idrepoDraftReprocessableExceptionTest() deleteApi(ApiName.IDREPODISCARDDRAFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponseDto); idrepoDraftService.idrepoUpdateDraft(ID, null, idRequestDto); - Mockito.verify(idrepoDraftService.idrepodiscardDraft(any()),times(1)); + Mockito.verify(idrepoDraftService.idrepoDiscardDraft(any()),times(1)); } @Test @@ -288,7 +288,7 @@ public void discardDraftSuccessTest() throws IdrepoDraftReprocessableException, when(registrationProcessorRestClientService. deleteApi(ApiName.IDREPODISCARDDRAFT, Lists.newArrayList(ID), "", "", IdResponseDTO.class)).thenReturn(discardIdresponseDto); - Boolean result= idrepoDraftService.idrepodiscardDraft(ID); + Boolean result= idrepoDraftService.idrepoDiscardDraft(ID); assertTrue(result); } }