Skip to content

Commit

Permalink
Merge pull request #1819 from Khuddusshariff0022/develop-MOSIP-28440
Browse files Browse the repository at this point in the history
[Mosip-28440] changes to compare the biometric records only with the …

Signed-off-by: khuddus shariff <[email protected]>
  • Loading branch information
vishwa-vyom authored and Khuddusshariff0022 committed Jan 24, 2024
1 parent c3b8646 commit cf5e6cb
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -592,12 +593,10 @@ public List<String> getProcessedOrProcessingRegIds(List<String> 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<String> getWithoutStatusCodes(List<String> matchedRegIds, String statusCode1, String statusCode2) {
return registrationRepositary.getWithoutStatusCodes(matchedRegIds, "REJECTED", "PROCESSED");
public List<RegistrationStatusEntity> getWithoutStatusCode(List<String> matchedRegIds, String statusCode) {
return registrationRepositary.getWithoutStatusCode(matchedRegIds, statusCode);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,15 +101,26 @@ public Set<String> getUniqueRegIds(String registrationId, String registrationTyp
if (!CollectionUtils.isEmpty(machedRefIds)) {
List<String> matchedRegIds = packetInfoDao.getAbisRefRegIdsByMatchedRefIds(machedRefIds);
if (!CollectionUtils.isEmpty(matchedRegIds)) {
List<String> processingRegIds = packetInfoDao.getWithoutStatusCodes(matchedRegIds,
RegistrationTransactionStatusCode.REJECTED.toString(), RegistrationTransactionStatusCode.PROCESSED.toString());
List<String> statusList=new ArrayList<>();
statusList.add(RegistrationTransactionStatusCode.PROCESSED.toString());
statusList.add(RegistrationTransactionStatusCode.PROCESSING.toString());
List<String> processedRegIds = packetInfoDao.getProcessedOrProcessingRegIds(matchedRegIds,
statusList);
uniqueRIDs = getUniqueRegIds(processedRegIds, registrationId, registrationType, stageName);
List<RegistrationStatusEntity> matchedRegistrationStatusEntities = packetInfoDao
.getWithoutStatusCode(matchedRegIds,
RegistrationStatusCode.REJECTED.toString());
List<RegistrationStatusEntity> processingRegistrationStatusEntities = matchedRegistrationStatusEntities
.stream()
.filter(e -> RegistrationStatusCode.PROCESSING.toString().equals(e.getStatusCode()))
.collect(Collectors.toList());
List<String> processingRegIds = processingRegistrationStatusEntities.stream()
.map(RegistrationStatusEntity::getRegId)
.collect(Collectors.toList());
List<String> matchedProcessedRegIds = matchedRegistrationStatusEntities.stream()
.map(RegistrationStatusEntity::getRegId).collect(Collectors.toList());
uniqueRIDs.addAll(processingRegIds);
Set<String> processedRegIds = getUniqueRegIds(matchedProcessedRegIds, registrationId,
registrationType,
stageName);
for(String rid:processedRegIds) {
if(!uniqueRIDs.contains(rid))
uniqueRIDs.add(rid);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> matchedRids = new ArrayList<>();


@InjectMocks
private ABISHandlerUtil abisHandlerUtil;

@Mock
private Utilities utilities;

@Mock
private PacketInfoManager<Identity, ApplicantInfoDto> packetInfoManager;

@Mock
private PacketInfoDao packetInfoDao;

@Mock
private IdRepoService idRepoService;

List<String> lst=new ArrayList<>();

@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
when(utilities.getLatestTransactionId(any(),any(),anyInt(), any())).thenReturn(latestTransactionId);

List<String> regBioRefIds = new ArrayList<>();
regBioRefIds.add("cf1c941a-142c-44f1-9543-4606b4a7884e");

when(packetInfoDao.getAbisRefIdByWorkflowInstanceId(any())).thenReturn(regBioRefIds);
when(utilities.getGetRegProcessorDemographicIdentity()).thenReturn(new String());

List<String> inprogressMatchedIds = new ArrayList<>();
inprogressMatchedIds.add("10002100820001420210108085100");
inprogressMatchedIds.add("10002100820001420210108085101");
inprogressMatchedIds.add("10002100820001420210108085102");

List<String> processedMatchedIds = new ArrayList<>();
processedMatchedIds.add("10002100820001420210108085103");
processedMatchedIds.add("10002100820001420210108085104");

matchedRids.addAll(inprogressMatchedIds);
matchedRids.addAll(processedMatchedIds);

List<AbisResponseDto> 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<AbisResponseDetDto> 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<String> 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<String> 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<String> 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<String> 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<String> matchedRids = new ArrayList<>();


@InjectMocks
private ABISHandlerUtil abisHandlerUtil;

@Mock
private Utilities utilities;

@Mock
private PacketInfoManager<Identity, ApplicantInfoDto> packetInfoManager;

@Mock
private PacketInfoDao packetInfoDao;

@Mock
private IdRepoService idRepoService;

List<String> lst=new ArrayList<>();

@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
when(utilities.getLatestTransactionId(any(),any(),anyInt(), any())).thenReturn(latestTransactionId);

List<String> regBioRefIds = new ArrayList<>();
regBioRefIds.add("cf1c941a-142c-44f1-9543-4606b4a7884e");

when(packetInfoDao.getAbisRefIdByWorkflowInstanceId(any())).thenReturn(regBioRefIds);
when(utilities.getGetRegProcessorDemographicIdentity()).thenReturn(new String());

List<RegistrationStatusEntity> 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<AbisResponseDto> 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<AbisResponseDetDto> 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<String> 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<String> 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<String> uniqueRids = abisHandlerUtil.getUniqueRegIds(registrationId, registrationType, ProviderStageName.BIO_DEDUPE);
Set<String> 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<String> uniqueRids = abisHandlerUtil.getUniqueRegIds(registrationId, registrationType,1, "", ProviderStageName.BIO_DEDUPE);
// expected not to pick processedMatchedIds list i.e 1 records..
assertEquals(1, uniqueRids.size());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ public interface RegistrationRepositary<T extends BaseRegistrationEntity, E> ext
public List<String> getProcessedOrProcessingRegIds(@Param("regIds") List<String> regIds,
@Param("statusCode") List<String> statusCode);

@Query("SELECT registration.regId FROM RegistrationStatusEntity registration WHERE registration.regId in :regIds AND registration.statusCode !=:statusCode1 AND registration.statusCode !=:statusCode2")
public List<String> getWithoutStatusCodes(@Param("regIds") List<String> 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<RegistrationStatusEntity> getWithoutStatusCode(@Param("regIds") List<String> 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<RegistrationStatusEntity> findByRegId(@Param("regId") String regId);

Expand Down

0 comments on commit cf5e6cb

Please sign in to comment.