Skip to content

Commit

Permalink
Merge pull request #1140 from MonobikashDas/1.1.4.6 (#1159)
Browse files Browse the repository at this point in the history
MOSIP-16638 : Ignore duplicate requests for same latest transaction i…

Co-authored-by: Sasikumar Ganesan <[email protected]>
  • Loading branch information
MonobikashDas and gsasikumar authored Aug 26, 2021
1 parent 68305da commit 5acb934
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ public MessageDTO process(MessageDTO object, String stageName) {

boolean isTransactionSuccessful = false;

boolean isDuplicateRequestForSameTransactionId = false;

InternalRegistrationStatusDto registrationStatusDto = new InternalRegistrationStatusDto();
try {
registrationStatusDto = registrationStatusService.getRegistrationStatus(registrationId);
Expand Down Expand Up @@ -202,6 +204,9 @@ && isValidCbeff(registrationId, registrationType)) {

}

if (abisHandlerUtil.getPacketStatus(registrationStatusDto).equalsIgnoreCase(AbisConstant.DUPLICATE_FOR_SAME_TRANSACTION_ID))
isDuplicateRequestForSameTransactionId = true;

registrationStatusDto.setRegistrationStageName(stageName);
isTransactionSuccessful = true;

Expand Down Expand Up @@ -275,22 +280,27 @@ && isValidCbeff(registrationId, registrationType)) {
object.setInternalError(Boolean.TRUE);
object.setIsValid(Boolean.FALSE);
} finally {
registrationStatusDto
.setLatestTransactionTypeCode(RegistrationTransactionTypeCode.BIOGRAPHIC_VERIFICATION.toString());
String moduleId = isTransactionSuccessful ? PlatformSuccessMessages.RPR_BIO_DEDUPE_SUCCESS.getCode()
: description.getCode();
String moduleName = ModuleName.BIO_DEDUPE.name();
registrationStatusService.updateRegistrationStatus(registrationStatusDto, moduleId, moduleName);
if (!isDuplicateRequestForSameTransactionId) {
registrationStatusDto
.setLatestTransactionTypeCode(RegistrationTransactionTypeCode.BIOGRAPHIC_VERIFICATION.toString());
String moduleId = isTransactionSuccessful ? PlatformSuccessMessages.RPR_BIO_DEDUPE_SUCCESS.getCode()
: description.getCode();
String moduleName = ModuleName.BIO_DEDUPE.name();
registrationStatusService.updateRegistrationStatus(registrationStatusDto, moduleId, moduleName);

regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(),
registrationId, "BioDedupeProcessor::" + registrationStatusDto.getLatestTransactionStatusCode());
regProcLogger.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(),
registrationId, "BioDedupeProcessor::" + registrationStatusDto.getLatestTransactionStatusCode());

String eventId = isTransactionSuccessful ? EventId.RPR_402.toString() : EventId.RPR_405.toString();
String eventName = isTransactionSuccessful ? EventName.UPDATE.toString() : EventName.EXCEPTION.toString();
String eventType = isTransactionSuccessful ? EventType.BUSINESS.toString() : EventType.SYSTEM.toString();

String eventId = isTransactionSuccessful ? EventId.RPR_402.toString() : EventId.RPR_405.toString();
String eventName = isTransactionSuccessful ? EventName.UPDATE.toString() : EventName.EXCEPTION.toString();
String eventType = isTransactionSuccessful ? EventType.BUSINESS.toString() : EventType.SYSTEM.toString();
auditLogRequestBuilder.createAuditRequestBuilder(description.getMessage(), eventId, eventName, eventType,
moduleId, moduleName, registrationId);
} else
regProcLogger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(),
registrationId, "Duplicate request received for same latest transaction id. This will be ignored.");

auditLogRequestBuilder.createAuditRequestBuilder(description.getMessage(), eventId, eventName, eventType,
moduleId, moduleName, registrationId);
}
return object;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package io.mosip.registration.processor.core.constant;

public interface AbisConstant {

static final String IDENTIFY = "IDENTIFY";

static final String TYPE = "type";

static final String ALL = "all";

static final String UIN = "UIN";

static final String PRE_ABIS_IDENTIFICATION = "PRE_ABIS_IDENTIFICATION";

static final String POST_ABIS_IDENTIFICATION = "POST_ABIS_IDENTIFICATION";

static final String PROCESSED = "PROCESSED";

static final String RE_REGISTER = "RE-REGISTER";


}
package io.mosip.registration.processor.core.constant;

public interface AbisConstant {

static final String IDENTIFY = "IDENTIFY";

static final String TYPE = "type";

static final String ALL = "all";

static final String UIN = "UIN";

static final String PRE_ABIS_IDENTIFICATION = "PRE_ABIS_IDENTIFICATION";

static final String POST_ABIS_IDENTIFICATION = "POST_ABIS_IDENTIFICATION";

static final String DUPLICATE_FOR_SAME_TRANSACTION_ID = "DUPLICATE_FOR_SAME_TRANSACTION_ID";

static final String PROCESSED = "PROCESSED";

static final String RE_REGISTER = "RE-REGISTER";


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import io.mosip.kernel.core.util.exception.JsonProcessingException;
import io.mosip.registration.processor.core.constant.ProviderStageName;
import io.mosip.registration.processor.core.code.AbisStatusCode;
import io.mosip.registration.processor.core.exception.PacketManagerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -119,31 +121,54 @@ public List<String> getUniqueRegIds(String registrationId, String registrationTy
* @return the packet status
*/
public String getPacketStatus(InternalRegistrationStatusDto registrationStatusDto) {
if (getMatchedRegIds(registrationStatusDto.getRegistrationId()).isEmpty()) {
// get all identify requests for latest transaction id
List<AbisRequestDto> identifyRequests = getAllIdentifyRequest(registrationStatusDto.getRegistrationId());

// if there are no identify requests present
if (CollectionUtils.isEmpty(identifyRequests))
return AbisConstant.PRE_ABIS_IDENTIFICATION;
}
return AbisConstant.POST_ABIS_IDENTIFICATION;
// if there are unprocessed pending identify request for same transaction id then consider it as duplicate
else if (isIdentifyRequestsPendingForLatestTransactionId(identifyRequests))
return AbisConstant.DUPLICATE_FOR_SAME_TRANSACTION_ID;
// else if all the identify requests processed for latest transaction id
else
return AbisConstant.POST_ABIS_IDENTIFICATION;
}

/**
* Gets the matched reg ids.
* This method returns all identify requests
*
* @param registrationId
* the registration id
* @return the matched reg ids
*/
private List<AbisRequestDto> getMatchedRegIds(String registrationId) {
private List<AbisRequestDto> getAllIdentifyRequest(String registrationId) {
String latestTransactionId = utilities.getLatestTransactionId(registrationId);

List<String> regBioRefIds = packetInfoDao.getAbisRefMatchedRefIdByRid(registrationId);

List<AbisRequestDto> abisRequestDtoList = new ArrayList<>();

if (!regBioRefIds.isEmpty()) {
abisRequestDtoList = packetInfoManager.getInsertOrIdentifyRequest(regBioRefIds.get(0), latestTransactionId);
List<AbisRequestDto> abisRequestDtoList = packetInfoManager.getInsertOrIdentifyRequest(regBioRefIds.get(0), latestTransactionId);
if (!CollectionUtils.isEmpty(abisRequestDtoList)) {
return abisRequestDtoList.stream().filter(reqDto ->
reqDto.getRequestType().equalsIgnoreCase(AbisStatusCode.IDENTIFY.toString())).collect(Collectors.toList());
}
}

return abisRequestDtoList;
return null;
}

/**
* This method returns all unprocessed identify requests
*
* @param identifyRequests
* @return
*/
private boolean isIdentifyRequestsPendingForLatestTransactionId(List<AbisRequestDto> identifyRequests) {
// check if any of the identify request is not processed for same transaction id
return identifyRequests.stream().filter(
identifyReq -> !identifyReq.getStatusCode().equalsIgnoreCase(AbisStatusCode.PROCESSED.toString()))
.findAny().isPresent();
}

/**
Expand Down

0 comments on commit 5acb934

Please sign in to comment.