From cf5e6cb78ce02d21d5777379fa97e857ef4854fa Mon Sep 17 00:00:00 2001 From: Vishwa Date: Mon, 22 Jan 2024 23:46:08 +0530 Subject: [PATCH] Merge pull request #1819 from Khuddusshariff0022/develop-MOSIP-28440 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Mosip-28440] changes to compare the biometric records only with the … Signed-off-by: khuddus shariff --- .../packet/storage/dao/PacketInfoDao.java | 7 +- .../packet/storage/utils/ABISHandlerUtil.java | 29 ++- .../storage/utils/ABISHandlerUtilTest.java | 246 +++++++++--------- .../repositary/RegistrationRepositary.java | 6 +- 4 files changed, 148 insertions(+), 140 deletions(-) diff --git a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/dao/PacketInfoDao.java b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/dao/PacketInfoDao.java index af857405162..f19ef8b3379 100644 --- a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/dao/PacketInfoDao.java +++ b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/dao/PacketInfoDao.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; +import io.mosip.registration.processor.status.entity.RegistrationStatusEntity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -592,12 +593,10 @@ public List getProcessedOrProcessingRegIds(List matchedRegIds, L * the matched reg ids * @param statusCode1 * the status code - * @param statusCode2 - * the status code * @return the processed or processing reg ids */ - public List getWithoutStatusCodes(List matchedRegIds, String statusCode1, String statusCode2) { - return registrationRepositary.getWithoutStatusCodes(matchedRegIds, "REJECTED", "PROCESSED"); + public List getWithoutStatusCode(List matchedRegIds, String statusCode) { + return registrationRepositary.getWithoutStatusCode(matchedRegIds, statusCode); } /** diff --git a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/utils/ABISHandlerUtil.java b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/utils/ABISHandlerUtil.java index d6ad7833d50..898f48a3c36 100644 --- a/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/utils/ABISHandlerUtil.java +++ b/registration-processor/registration-processor-info-storage-service/src/main/java/io/mosip/registration/processor/packet/storage/utils/ABISHandlerUtil.java @@ -13,6 +13,8 @@ import io.mosip.registration.processor.core.code.AbisStatusCode; import io.mosip.registration.processor.core.constant.ProviderStageName; import io.mosip.registration.processor.core.exception.PacketManagerException; +import io.mosip.registration.processor.status.code.RegistrationStatusCode; +import io.mosip.registration.processor.status.entity.RegistrationStatusEntity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -99,15 +101,26 @@ public Set getUniqueRegIds(String registrationId, String registrationTyp if (!CollectionUtils.isEmpty(machedRefIds)) { List matchedRegIds = packetInfoDao.getAbisRefRegIdsByMatchedRefIds(machedRefIds); if (!CollectionUtils.isEmpty(matchedRegIds)) { - List processingRegIds = packetInfoDao.getWithoutStatusCodes(matchedRegIds, - RegistrationTransactionStatusCode.REJECTED.toString(), RegistrationTransactionStatusCode.PROCESSED.toString()); - List statusList=new ArrayList<>(); - statusList.add(RegistrationTransactionStatusCode.PROCESSED.toString()); - statusList.add(RegistrationTransactionStatusCode.PROCESSING.toString()); - List processedRegIds = packetInfoDao.getProcessedOrProcessingRegIds(matchedRegIds, - statusList); - uniqueRIDs = getUniqueRegIds(processedRegIds, registrationId, registrationType, stageName); + List matchedRegistrationStatusEntities = packetInfoDao + .getWithoutStatusCode(matchedRegIds, + RegistrationStatusCode.REJECTED.toString()); + List processingRegistrationStatusEntities = matchedRegistrationStatusEntities + .stream() + .filter(e -> RegistrationStatusCode.PROCESSING.toString().equals(e.getStatusCode())) + .collect(Collectors.toList()); + List processingRegIds = processingRegistrationStatusEntities.stream() + .map(RegistrationStatusEntity::getRegId) + .collect(Collectors.toList()); + List matchedProcessedRegIds = matchedRegistrationStatusEntities.stream() + .map(RegistrationStatusEntity::getRegId).collect(Collectors.toList()); uniqueRIDs.addAll(processingRegIds); + Set processedRegIds = getUniqueRegIds(matchedProcessedRegIds, registrationId, + registrationType, + stageName); + for(String rid:processedRegIds) { + if(!uniqueRIDs.contains(rid)) + uniqueRIDs.add(rid); + } } } } diff --git a/registration-processor/registration-processor-info-storage-service/src/test/java/io/mosip/registration/processor/packet/storage/utils/ABISHandlerUtilTest.java b/registration-processor/registration-processor-info-storage-service/src/test/java/io/mosip/registration/processor/packet/storage/utils/ABISHandlerUtilTest.java index dce4b2c684c..3ed2d2edcbc 100644 --- a/registration-processor/registration-processor-info-storage-service/src/test/java/io/mosip/registration/processor/packet/storage/utils/ABISHandlerUtilTest.java +++ b/registration-processor/registration-processor-info-storage-service/src/test/java/io/mosip/registration/processor/packet/storage/utils/ABISHandlerUtilTest.java @@ -15,6 +15,8 @@ import io.mosip.registration.processor.packet.storage.dao.PacketInfoDao; import io.mosip.registration.processor.packet.storage.dto.ApplicantInfoDto; import io.mosip.registration.processor.packet.storage.mapper.PacketInfoMapper; +import io.mosip.registration.processor.status.code.RegistrationStatusCode; +import io.mosip.registration.processor.status.entity.RegistrationStatusEntity; import org.assertj.core.util.Lists; import org.junit.Before; import org.junit.Test; @@ -45,129 +47,125 @@ @PowerMockIgnore({ "javax.management.*", "javax.net.ssl.*","com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*" }) public class ABISHandlerUtilTest { - private static final String registrationId = "10002100820001420210108085956"; - private static final String registrationType = "NEW"; - private static final String latestTransactionId = "123-456-789"; - List matchedRids = new ArrayList<>(); - - - @InjectMocks - private ABISHandlerUtil abisHandlerUtil; - - @Mock - private Utilities utilities; - - @Mock - private PacketInfoManager packetInfoManager; - - @Mock - private PacketInfoDao packetInfoDao; - - @Mock - private IdRepoService idRepoService; - - List lst=new ArrayList<>(); - - @Before - public void setup() throws Exception { - MockitoAnnotations.initMocks(this); - when(utilities.getLatestTransactionId(any(),any(),anyInt(), any())).thenReturn(latestTransactionId); - - List regBioRefIds = new ArrayList<>(); - regBioRefIds.add("cf1c941a-142c-44f1-9543-4606b4a7884e"); - - when(packetInfoDao.getAbisRefIdByWorkflowInstanceId(any())).thenReturn(regBioRefIds); - when(utilities.getGetRegProcessorDemographicIdentity()).thenReturn(new String()); - - List inprogressMatchedIds = new ArrayList<>(); - inprogressMatchedIds.add("10002100820001420210108085100"); - inprogressMatchedIds.add("10002100820001420210108085101"); - inprogressMatchedIds.add("10002100820001420210108085102"); - - List processedMatchedIds = new ArrayList<>(); - processedMatchedIds.add("10002100820001420210108085103"); - processedMatchedIds.add("10002100820001420210108085104"); - - matchedRids.addAll(inprogressMatchedIds); - matchedRids.addAll(processedMatchedIds); - - List abisResponseDtoList = new ArrayList<>(); - matchedRids.forEach(matchedRid -> { - AbisResponseDto abisResponseDto = new AbisResponseDto(); - abisResponseDto.setId(matchedRid); - abisResponseDtoList.add(abisResponseDto); - }); - - - lst.add(RegistrationTransactionStatusCode.PROCESSED.toString());lst.add(RegistrationTransactionStatusCode.PROCESSING.toString()); - - - when(packetInfoManager.getAbisResponseRecords(regBioRefIds.get(0), - latestTransactionId, AbisConstant.IDENTIFY)).thenReturn(abisResponseDtoList); - - List abisResponseDetDtoList = new ArrayList<>(); - - matchedRids.forEach(matchedRid -> { - AbisResponseDetDto abisResponseDto = new AbisResponseDetDto(); - abisResponseDto.setMatchedBioRefId(matchedRid); - abisResponseDetDtoList.add(abisResponseDto); - }); - for (AbisResponseDetDto dto : abisResponseDetDtoList) { - AbisResponseDetDto responseDetDto = new AbisResponseDetDto(); - responseDetDto.setMatchedBioRefId(dto.getMatchedBioRefId()); - when(packetInfoManager.getAbisResponseDetails(dto.getMatchedBioRefId())).thenReturn(Lists.newArrayList(responseDetDto)); - } - - when(packetInfoDao.getAbisRefRegIdsByMatchedRefIds(matchedRids)).thenReturn(matchedRids); - - when(packetInfoDao.getWithoutStatusCodes(matchedRids, RegistrationTransactionStatusCode.REJECTED.toString(), - RegistrationTransactionStatusCode.PROCESSED.toString())).thenReturn(inprogressMatchedIds); - when(packetInfoDao.getProcessedOrProcessingRegIds(matchedRids, - lst)).thenReturn(processedMatchedIds); - - when(idRepoService.getUinByRid(processedMatchedIds.get(0), new String())).thenReturn("123456789"); - when(idRepoService.getUinByRid(processedMatchedIds.get(1), new String())).thenReturn("987654321"); - - } - - @Test - public void testProcesssedWithUniqueUin() throws ApisResourceAccessException, JsonProcessingException, PacketManagerException, IOException, io.mosip.kernel.core.exception.IOException { - - Set uniqueRids = abisHandlerUtil.getUniqueRegIds(registrationId, registrationType, 1, "", ProviderStageName.BIO_DEDUPE); - - assertEquals(matchedRids.size(), uniqueRids.size()); - } - - @Test - public void testProcesssedWithSameUin() throws ApisResourceAccessException, JsonProcessingException, PacketManagerException, IOException, io.mosip.kernel.core.exception.IOException { - - when(idRepoService.getUinByRid(anyString(), anyString())).thenReturn("987654321"); - - Set uniqueRids = abisHandlerUtil.getUniqueRegIds(registrationId, registrationType,1, "", ProviderStageName.BIO_DEDUPE); - // expected to pick only 1 rid from processedMatchedIds list. Total should be 3(inprogress) + 1(processed) - assertEquals(4, uniqueRids.size()); - } - - @Test - public void testDonotReturnRejected() throws ApisResourceAccessException, JsonProcessingException, PacketManagerException, IOException, io.mosip.kernel.core.exception.IOException { - - when(packetInfoDao.getWithoutStatusCodes(matchedRids, RegistrationTransactionStatusCode.REJECTED.toString(), - RegistrationTransactionStatusCode.PROCESSED.toString())).thenReturn(Lists.newArrayList()); - - Set uniqueRids = abisHandlerUtil.getUniqueRegIds(registrationId, registrationType,1, "", ProviderStageName.BIO_DEDUPE); - // expected to pick only rocessedMatchedIds list i.e 2 records. - assertEquals(2, uniqueRids.size()); - } - - @Test - public void testReturnAllInprogress() throws ApisResourceAccessException, JsonProcessingException, PacketManagerException, IOException, io.mosip.kernel.core.exception.IOException { - - when(packetInfoDao.getProcessedOrProcessingRegIds(matchedRids, - lst)).thenReturn(Lists.newArrayList()); - - Set uniqueRids = abisHandlerUtil.getUniqueRegIds(registrationId, registrationType,1, "", ProviderStageName.BIO_DEDUPE); - // expected not to pick rocessedMatchedIds list i.e 3 records. - assertEquals(3, uniqueRids.size()); - } + private static final String registrationId = "10002100820001420210108085956"; + private static final String registrationType = "NEW"; + private static final String latestTransactionId = "123-456-789"; + List matchedRids = new ArrayList<>(); + + + @InjectMocks + private ABISHandlerUtil abisHandlerUtil; + + @Mock + private Utilities utilities; + + @Mock + private PacketInfoManager packetInfoManager; + + @Mock + private PacketInfoDao packetInfoDao; + + @Mock + private IdRepoService idRepoService; + + List lst=new ArrayList<>(); + + @Before + public void setup() throws Exception { + MockitoAnnotations.initMocks(this); + when(utilities.getLatestTransactionId(any(),any(),anyInt(), any())).thenReturn(latestTransactionId); + + List regBioRefIds = new ArrayList<>(); + regBioRefIds.add("cf1c941a-142c-44f1-9543-4606b4a7884e"); + + when(packetInfoDao.getAbisRefIdByWorkflowInstanceId(any())).thenReturn(regBioRefIds); + when(utilities.getGetRegProcessorDemographicIdentity()).thenReturn(new String()); + + List registrationStatusEntityList = new ArrayList<>(); + + RegistrationStatusEntity registrationEntity1 = new RegistrationStatusEntity(); + registrationEntity1.setRegId("10002100820001420210108085103"); + registrationEntity1.setStatusCode(RegistrationStatusCode.PROCESSED.toString()); + registrationStatusEntityList.add(registrationEntity1); + RegistrationStatusEntity registrationEntity2 = new RegistrationStatusEntity(); + registrationEntity2.setRegId("10002100820001420210108085100"); + registrationEntity2.setStatusCode(RegistrationStatusCode.PROCESSING.toString()); + registrationStatusEntityList.add(registrationEntity2); + RegistrationStatusEntity registrationEntity3 = new RegistrationStatusEntity(); + registrationEntity3.setRegId("10002100820001420210108085102"); + registrationEntity3.setStatusCode(RegistrationStatusCode.PROCESSED.toString()); + registrationStatusEntityList.add(registrationEntity3); + matchedRids.add("10002100820001420210108085100"); + matchedRids.add("10002100820001420210108085103"); + matchedRids.add("10002100820001420210108085101");// REJECTED + matchedRids.add("10002100820001420210108085102"); + + List abisResponseDtoList = new ArrayList<>(); + matchedRids.forEach(matchedRid -> { + AbisResponseDto abisResponseDto = new AbisResponseDto(); + abisResponseDto.setId(matchedRid); + abisResponseDtoList.add(abisResponseDto); + }); + + lst.add(RegistrationTransactionStatusCode.PROCESSED.toString());lst.add(RegistrationTransactionStatusCode.PROCESSING.toString()); + + when(packetInfoManager.getAbisResponseRecords(regBioRefIds.get(0), + latestTransactionId, AbisConstant.IDENTIFY)).thenReturn(abisResponseDtoList); + + List abisResponseDetDtoList = new ArrayList<>(); + matchedRids.forEach(matchedRid -> { + AbisResponseDetDto abisResponseDto = new AbisResponseDetDto(); + abisResponseDto.setMatchedBioRefId(matchedRid); + abisResponseDetDtoList.add(abisResponseDto); + }); + for (AbisResponseDetDto dto : abisResponseDetDtoList) { + AbisResponseDetDto responseDetDto = new AbisResponseDetDto(); + responseDetDto.setMatchedBioRefId(dto.getMatchedBioRefId()); + when(packetInfoManager.getAbisResponseDetails(dto.getMatchedBioRefId())).thenReturn(Lists.newArrayList(responseDetDto)); + } + when(packetInfoDao.getAbisRefRegIdsByMatchedRefIds(matchedRids)).thenReturn(matchedRids); + when(packetInfoDao.getWithoutStatusCode(matchedRids, RegistrationStatusCode.REJECTED.toString())) + .thenReturn(registrationStatusEntityList); + when(idRepoService.getUinByRid("10002100820001420210108085103", new String())).thenReturn("123456789"); + when(idRepoService.getUinByRid("10002100820001420210108085102", new String())).thenReturn("987654321"); + } + + @Test + public void testProcesssedWithUniqueUin() throws ApisResourceAccessException, JsonProcessingException, PacketManagerException, IOException, io.mosip.kernel.core.exception.IOException { + + Set uniqueRids = abisHandlerUtil.getUniqueRegIds(registrationId, registrationType, 1, "", ProviderStageName.BIO_DEDUPE); +// expected to pick 2 rids from processedMatchedIds list because different uin. + // Total should be 1(inprogress) + 2(processed) + assertEquals(3, uniqueRids.size()); + } + + @Test + public void testProcesssedWithSameUin() throws ApisResourceAccessException, JsonProcessingException, PacketManagerException, IOException, io.mosip.kernel.core.exception.IOException { + + when(idRepoService.getUinByRid(anyString(), anyString())).thenReturn("987654321"); + + Set uniqueRids = abisHandlerUtil.getUniqueRegIds(registrationId, registrationType,1, "", ProviderStageName.BIO_DEDUPE); + // expected to pick only 1 rid from processedMatchedIds list because same uin. Total should be 1(inprogress) + 1(processed) + assertEquals(2, uniqueRids.size()); + } + + @Test + public void testDonotReturnRejected() throws ApisResourceAccessException, JsonProcessingException, PacketManagerException, IOException, io.mosip.kernel.core.exception.IOException { + +// List uniqueRids = abisHandlerUtil.getUniqueRegIds(registrationId, registrationType, ProviderStageName.BIO_DEDUPE); + Set uniqueRids= abisHandlerUtil.getUniqueRegIds(registrationId,registrationType,1,"",ProviderStageName.BIO_DEDUPE); + // expected to pick only processingandprocessed list i.e 3 records. + assertEquals(3, uniqueRids.size()); + } + + @Test + public void testReturnAllInprogress() throws ApisResourceAccessException, JsonProcessingException, PacketManagerException, IOException, io.mosip.kernel.core.exception.IOException { + + when(idRepoService.getUinByRid(anyString(), anyString())).thenReturn(null); + + Set uniqueRids = abisHandlerUtil.getUniqueRegIds(registrationId, registrationType,1, "", ProviderStageName.BIO_DEDUPE); + // expected not to pick processedMatchedIds list i.e 1 records.. + assertEquals(1, uniqueRids.size()); + } } diff --git a/registration-processor/registration-processor-registration-status-service-impl/src/main/java/io/mosip/registration/processor/status/repositary/RegistrationRepositary.java b/registration-processor/registration-processor-registration-status-service-impl/src/main/java/io/mosip/registration/processor/status/repositary/RegistrationRepositary.java index 73cacb1a5d7..fc9a51848e0 100644 --- a/registration-processor/registration-processor-registration-status-service-impl/src/main/java/io/mosip/registration/processor/status/repositary/RegistrationRepositary.java +++ b/registration-processor/registration-processor-registration-status-service-impl/src/main/java/io/mosip/registration/processor/status/repositary/RegistrationRepositary.java @@ -31,10 +31,8 @@ public interface RegistrationRepositary ext public List getProcessedOrProcessingRegIds(@Param("regIds") List regIds, @Param("statusCode") List statusCode); - @Query("SELECT registration.regId FROM RegistrationStatusEntity registration WHERE registration.regId in :regIds AND registration.statusCode !=:statusCode1 AND registration.statusCode !=:statusCode2") - public List getWithoutStatusCodes(@Param("regIds") List regIds, - @Param("statusCode1") String statusCode1, @Param("statusCode2") String statusCode2); - + @Query("SELECT registration FROM RegistrationStatusEntity registration WHERE registration.id in :regIds and registration.statusCode !=:statusCode") + public List getWithoutStatusCode(@Param("regIds") List regIds, @Param("statusCode") String statusCode); @Query("SELECT registration FROM RegistrationStatusEntity registration WHERE registration.regId = :regId AND registration.isDeleted =false AND registration.isActive=true") public List findByRegId(@Param("regId") String regId);