Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MOSIP-29868] Code fix after testing #1841

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,107 +1,115 @@
package io.mosip.registration.processor.stages.demodedupe;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import io.mosip.registration.processor.core.packet.dto.Identity;
import io.mosip.registration.processor.core.packet.dto.abis.RegBioRefDto;
import io.mosip.registration.processor.core.spi.packetmanager.PacketInfoManager;
import io.mosip.registration.processor.packet.storage.dto.ApplicantInfoDto;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import io.mosip.kernel.core.logger.spi.Logger;
import io.mosip.registration.processor.core.constant.LoggerFileConstant;
import io.mosip.registration.processor.core.logger.RegProcessorLogger;
import io.mosip.registration.processor.core.packet.dto.demographicinfo.DemographicInfoDto;
import io.mosip.registration.processor.packet.storage.dao.PacketInfoDao;
import io.mosip.registration.processor.stages.app.constants.DemoDedupeConstants;
import io.mosip.registration.processor.status.service.RegistrationStatusService;

/**
* The Class DemoDedupe.
*
* @author M1048358 Alok Ranjan
* @author M1048860 Kiran Raj
*/
@Component
public class DemoDedupe {

/** The reg proc logger. */
private static Logger regProcLogger = RegProcessorLogger.getLogger(DemoDedupe.class);

/** The env. */
@Autowired
private Environment env;

@Autowired
private RegistrationStatusService registrationStatusService;

/** The packet info dao. */
@Autowired
private PacketInfoDao packetInfoDao;

/** The packet info manager. */
@Autowired
private PacketInfoManager<Identity, ApplicantInfoDto> packetInfoManager;

/**
* Perform dedupe.
*
* @param refId
* the ref id
* @return the list
*/
public List<DemographicInfoDto> performDedupe(String refId) {
regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REFFERENCEID.toString(), refId,
"DemoDedupe::performDedupe()::entry");

List<DemographicInfoDto> applicantDemoDto = packetInfoDao.findDemoById(refId);
List<DemographicInfoDto> matchedIdsWithUin;
List<DemographicInfoDto> demographicInfoDtos;
Set<DemographicInfoDto> infoDtos = new HashSet<>();
for (DemographicInfoDto demoDto : applicantDemoDto) {
infoDtos.addAll(packetInfoDao.getAllDemographicInfoDtos(demoDto.getName(), demoDto.getGenderCode(),
demoDto.getDob(), demoDto.getLangCode()));
}
matchedIdsWithUin = getAllDemographicInfoDtosWithUin(infoDtos);
demographicInfoDtos = filterByRefIdAvailability(matchedIdsWithUin);

regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REFFERENCEID.toString(), refId,
"DemoDedupe::performDedupe()::exit");
return demographicInfoDtos;
}

private List<DemographicInfoDto> getAllDemographicInfoDtosWithUin(
Set<DemographicInfoDto> duplicateDemographicDtos) {
List<DemographicInfoDto> demographicInfoDtosWithUin = new ArrayList<>();
for (DemographicInfoDto demographicDto : duplicateDemographicDtos) {
if (registrationStatusService.checkUinAvailabilityForRid(demographicDto.getRegId())) {
demographicInfoDtosWithUin.add(demographicDto);
}

}
return demographicInfoDtosWithUin;
}

private List<DemographicInfoDto> filterByRefIdAvailability(List<DemographicInfoDto> duplicateDemographicDtos) {
List<DemographicInfoDto> demographicInfoDtosWithRefId = new ArrayList<>();
if (CollectionUtils.isNotEmpty(duplicateDemographicDtos)) {
List<String> regIds = duplicateDemographicDtos.stream().map(dto -> dto.getRegId()).collect(Collectors.toList());
List<RegBioRefDto> finalRegBioRefDtos = packetInfoManager.getBioRefIdsByRegIds(regIds);
if (CollectionUtils.isNotEmpty(finalRegBioRefDtos)) {
List<String> finalRegIds = finalRegBioRefDtos.stream().map(dto -> dto.getRegId()).collect(Collectors.toList());
demographicInfoDtosWithRefId.addAll(duplicateDemographicDtos.stream().filter(
dto -> finalRegIds.contains(dto.getRegId())).collect(Collectors.toList()));
}
}
return demographicInfoDtosWithRefId;
}


}
package io.mosip.registration.processor.stages.demodedupe;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import io.mosip.kernel.core.logger.spi.Logger;
import io.mosip.registration.processor.core.constant.LoggerFileConstant;
import io.mosip.registration.processor.core.logger.RegProcessorLogger;
import io.mosip.registration.processor.core.packet.dto.Identity;
import io.mosip.registration.processor.core.packet.dto.abis.RegBioRefDto;
import io.mosip.registration.processor.core.packet.dto.demographicinfo.DemographicInfoDto;
import io.mosip.registration.processor.core.spi.packetmanager.PacketInfoManager;
import io.mosip.registration.processor.packet.storage.dao.PacketInfoDao;
import io.mosip.registration.processor.packet.storage.dto.ApplicantInfoDto;
import io.mosip.registration.processor.status.service.RegistrationStatusService;

/**
* The Class DemoDedupe.
*
* @author M1048358 Alok Ranjan
* @author M1048860 Kiran Raj
*/
@Component
public class DemoDedupe {

/** The reg proc logger. */
private static Logger regProcLogger = RegProcessorLogger.getLogger(DemoDedupe.class);

/** The env. */
@Autowired
private Environment env;

@Autowired
private RegistrationStatusService registrationStatusService;

/** The packet info dao. */
@Autowired
private PacketInfoDao packetInfoDao;

/** The packet info manager. */
@Autowired
private PacketInfoManager<Identity, ApplicantInfoDto> packetInfoManager;

@Value("${mosip.regproc.demo.dedupe.skip-refid-check-for-infant-dedupe:false}")
private boolean skipRefIdCheckForInfantDeduplication;

/**
* Perform dedupe.
*
* @param refId
* the ref id
* @return the list
*/
public List<DemographicInfoDto> performDedupe(String refId, boolean isInfant) {
regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REFFERENCEID.toString(), refId,
"DemoDedupe::performDedupe()::entry");

List<DemographicInfoDto> applicantDemoDto = packetInfoDao.findDemoById(refId);
List<DemographicInfoDto> matchedIdsWithUin;
List<DemographicInfoDto> demographicInfoDtos;
Set<DemographicInfoDto> infoDtos = new HashSet<>();
for (DemographicInfoDto demoDto : applicantDemoDto) {
infoDtos.addAll(packetInfoDao.getAllDemographicInfoDtos(demoDto.getName(), demoDto.getGenderCode(),
demoDto.getDob(), demoDto.getLangCode()));
}
matchedIdsWithUin = getAllDemographicInfoDtosWithUin(infoDtos);
if (isInfant && skipRefIdCheckForInfantDeduplication) {
demographicInfoDtos = new ArrayList<>();
demographicInfoDtos.addAll(matchedIdsWithUin);
} else {
demographicInfoDtos = filterByRefIdAvailability(matchedIdsWithUin);
}

regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REFFERENCEID.toString(), refId,
"DemoDedupe::performDedupe()::exit");
return demographicInfoDtos;
}

private List<DemographicInfoDto> getAllDemographicInfoDtosWithUin(
Set<DemographicInfoDto> duplicateDemographicDtos) {
List<DemographicInfoDto> demographicInfoDtosWithUin = new ArrayList<>();
for (DemographicInfoDto demographicDto : duplicateDemographicDtos) {
if (registrationStatusService.checkUinAvailabilityForRid(demographicDto.getRegId())) {
demographicInfoDtosWithUin.add(demographicDto);
}

}
return demographicInfoDtosWithUin;
}

private List<DemographicInfoDto> filterByRefIdAvailability(List<DemographicInfoDto> duplicateDemographicDtos) {
List<DemographicInfoDto> demographicInfoDtosWithRefId = new ArrayList<>();
if (CollectionUtils.isNotEmpty(duplicateDemographicDtos)) {
List<String> regIds = duplicateDemographicDtos.stream().map(dto -> dto.getRegId()).collect(Collectors.toList());
List<RegBioRefDto> finalRegBioRefDtos = packetInfoManager.getBioRefIdsByRegIds(regIds);
if (CollectionUtils.isNotEmpty(finalRegBioRefDtos)) {
List<String> finalRegIds = finalRegBioRefDtos.stream().map(dto -> dto.getRegId()).collect(Collectors.toList());
demographicInfoDtosWithRefId.addAll(duplicateDemographicDtos.stream().filter(
dto -> finalRegIds.contains(dto.getRegId())).collect(Collectors.toList()));
}
}
return demographicInfoDtosWithRefId;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ private List<DemographicInfoDto> performDemoDedupe(InternalRegistrationStatusDto
JsonProcessingException, DataShareException, IOException {
String registrationId = registrationStatusDto.getRegistrationId();
// Potential Duplicate Ids after performing demo dedupe
List<DemographicInfoDto> duplicateDtos = demoDedupe.performDedupe(registrationStatusDto.getRegistrationId());
List<DemographicInfoDto> duplicateDtos = demoDedupe.performDedupe(registrationStatusDto.getRegistrationId(),
isInfant);
List<String> matchedRidsWithoutRejected = new ArrayList<>();
List<String> matchedRegIds;
if (!duplicateDtos.isEmpty()) {
Expand Down
Loading
Loading