diff --git a/resident/resident-service/src/main/java/io/mosip/resident/util/PerpetualVidUtil.java b/resident/resident-service/src/main/java/io/mosip/resident/util/PerpetualVidUtil.java index 596a4d949b..4876564fa3 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/util/PerpetualVidUtil.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/util/PerpetualVidUtil.java @@ -100,7 +100,14 @@ public ResponseWrapper>> retrieveVidsfromUin(String uin, int + e.getMessage() + ExceptionUtils.getStackTrace(e)); throw new ApisResourceAccessException("Unable to retrieve VID : " + e.getMessage()); } - + ResponseWrapper>> res = new ResponseWrapper>>(); + res.setId(residentVidGetId); + res.setVersion(newVersion); + res.setResponsetime(DateUtils.getUTCCurrentDateTimeString()); + if(response.getErrors()!=null && !response.getErrors().isEmpty()){ + res.setResponse(List.of()); + return res; + } List> filteredList = ((List>) response.getResponse()).stream() .map(map -> { LinkedHashMap lhm = new LinkedHashMap(map); @@ -112,10 +119,6 @@ public ResponseWrapper>> retrieveVidsfromUin(String uin, int }) .filter(map1 -> map1.get(TRANSACTIONS_LEFT_COUNT) == null || (int) map1.get(TRANSACTIONS_LEFT_COUNT) > 0) .collect(Collectors.toList()); - ResponseWrapper>> res = new ResponseWrapper>>(); - res.setId(residentVidGetId); - res.setVersion(newVersion); - res.setResponsetime(DateUtils.getUTCCurrentDateTimeString()); res.setResponse(filteredList); return res; } diff --git a/resident/resident-service/src/test/java/io/mosip/resident/util/PerpetualVidUtilTest.java b/resident/resident-service/src/test/java/io/mosip/resident/util/PerpetualVidUtilTest.java index 143a07624a..f8c5c89665 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/util/PerpetualVidUtilTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/util/PerpetualVidUtilTest.java @@ -1,6 +1,8 @@ package io.mosip.resident.util; import com.fasterxml.jackson.databind.ObjectMapper; +import io.mosip.kernel.core.exception.ServiceError; +import io.mosip.resident.constant.ResidentErrorCode; import io.mosip.resident.dto.ResponseWrapper; import io.mosip.resident.exception.ApisResourceAccessException; import io.mosip.resident.exception.ResidentServiceCheckedException; @@ -141,5 +143,21 @@ public void testRetrieveVidsfromUin_Exception() throws ResidentServiceCheckedExc perpetualVidUtil.retrieveVidsfromUin(uin, timeZoneOffset, locale); }); } + + @Test + public void testRetrieveVidsfromUin_EmtpyArray() throws ApisResourceAccessException, ResidentServiceCheckedException { + String uin = "123456789012"; + int timeZoneOffset = 0; + String locale = "en"; + + ResponseWrapper>> responseWrapper = new ResponseWrapper<>(); + responseWrapper.setErrors(List.of(new ServiceError(ResidentErrorCode.NO_RECORDS_FOUND.getErrorCode(), + ResidentErrorCode.NO_RECORDS_FOUND.getErrorMessage()))); + + when(residentServiceRestClient.getApi(anyString(), eq(ResponseWrapper.class))).thenReturn(responseWrapper); + ResponseWrapper>> result = perpetualVidUtil.retrieveVidsfromUin(uin, timeZoneOffset, locale); + assertNotNull(result); + assertEquals(0, result.getResponse().size()); + } }