Skip to content

Commit

Permalink
[Mosip_31365] calling discaedDraft api only when we get the non repro…
Browse files Browse the repository at this point in the history
…cessable exception

Signed-off-by: khuddus shariff <[email protected]>
  • Loading branch information
Khuddusshariff0022 committed Mar 13, 2024
1 parent de24cdf commit 4b5e81c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,12 @@ 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()) {
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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -141,18 +141,18 @@ 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());
}
}
regProcLogger.debug("idrepoPublishDraft exit " + 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<String> pathsegments = new ArrayList<String>();
pathsegments.add(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));

}

Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}

0 comments on commit 4b5e81c

Please sign in to comment.