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-30287-clone-1201-validation-required-before-persist-extracted-t… #891

Draft
wants to merge 1 commit into
base: release-1.2.0.1
Choose a base branch
from
Draft
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
MOSIP-30287-clone-1201-validation-required-before-persist-extracted-t…
…emplate-data-in-min-io

Signed-off-by: Neha Farheen <neha.61092365@ltimindtree.com>
  • Loading branch information
Neha Farheen committed Jan 22, 2024
commit a6c7e0f95862bd6671bbc00a87b5ac685b3ab4a7
Original file line number Diff line number Diff line change
@@ -89,6 +89,8 @@ public enum IdRepoErrorConstants {

UIN_GENERATION_FAILED("IDR-IDS-011","Failed to generate UIN"),

INVALID_BIOMETRIC("IDR-IDS-012", "Failed to extract the valid biometric data"),

// VID Service

/** The invalid vid. */
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import static io.mosip.idrepository.core.constant.IdRepoConstants.EXTRACTION_FORMAT_QUERY_PARAM_SUFFIX;
import static io.mosip.idrepository.core.constant.IdRepoErrorConstants.BIO_EXTRACTION_ERROR;
import static io.mosip.idrepository.core.constant.IdRepoErrorConstants.UNKNOWN_ERROR;
import static io.mosip.idrepository.core.constant.IdRepoErrorConstants.INVALID_BIOMETRIC;

import java.util.List;
import java.util.Map;
@@ -72,12 +73,27 @@ public CompletableFuture<List<BIR>> extractTemplate(String uinHash, String fileN
String extractionType, String extractionFormat, List<BIR> birsForModality) throws IdRepoAppException {
try {
String extractionFileName = fileName.split("\\.")[0] + DOT + getModalityForFormat(extractionType) + DOT + extractionFormat;
Map<String, String> formatFlag = Map.of(getFormatFlag(extractionType), extractionFormat);
try {
if (objectStoreHelper.biometricObjectExists(uinHash, extractionFileName)) {
mosipLogger.info(IdRepoSecurityManager.getUser(), this.getClass().getSimpleName(), EXTRACT_TEMPLATE,
"RETURNING EXISTING EXTRACTED BIOMETRICS FOR FORMAT: " + extractionType +" : "+ extractionFormat);
byte[] xmlBytes = objectStoreHelper.getBiometricObject(uinHash, extractionFileName);
List<BIR> existingBirs = cbeffUtil.getBIRDataFromXML(xmlBytes);
List<BIR> existingBirs;
try {
existingBirs = cbeffUtil.getBIRDataFromXML(xmlBytes);
} catch (Exception e) {
existingBirs = List.of();
mosipLogger.error(IdRepoSecurityManager.getUser(), this.getClass().getSimpleName(),
EXTRACT_TEMPLATE, e.getMessage());
}
if (!validateCbeff(existingBirs)) {
List<BIR> extractedBiometrics = extractBiometricTemplate(formatFlag, birsForModality);
objectStoreHelper.putBiometricObject(uinHash, extractionFileName,
cbeffUtil.createXML(extractedBiometrics));
return CompletableFuture.completedFuture(extractedBiometrics);
}

return CompletableFuture.completedFuture(existingBirs);
}
} catch (ObjectStoreAdapterException e) {
@@ -87,13 +103,16 @@ public CompletableFuture<List<BIR>> extractTemplate(String uinHash, String fileN

mosipLogger.info(IdRepoSecurityManager.getUser(), this.getClass().getSimpleName(), EXTRACT_TEMPLATE,
"EXTRATCING BIOMETRICS FOR FORMAT: " + extractionType +" : "+ extractionFormat);
Map<String, String> formatFlag = Map.of(getFormatFlag(extractionType), extractionFormat);

List<BIR> extractedBiometrics = extractBiometricTemplate(formatFlag, birsForModality);
if (!extractedBiometrics.isEmpty()) {
objectStoreHelper.putBiometricObject(uinHash, extractionFileName, cbeffUtil.createXML(extractedBiometrics));
}
return CompletableFuture.completedFuture(extractedBiometrics);
} catch (BiometricExtractionException e) {
if(e.getErrorCode().equalsIgnoreCase(INVALID_BIOMETRIC.getErrorCode())) {
throw e;
}
mosipLogger.error(IdRepoSecurityManager.getUser(), this.getClass().getSimpleName(), EXTRACT_TEMPLATE, e.getMessage());
throw new IdRepoAppException(BIO_EXTRACTION_ERROR, e);
} catch (Exception e) {
@@ -140,6 +159,10 @@ private List<BIR> extractBiometricTemplate(Map<String, String> extractionFormats
bioExtractReq.setExtractionFormats(extractionFormats);

BioExtractResponseDTO bioExtractResponseDTO = extractBiometrics(bioExtractReq);
if (!validateCbeff(bioExtractResponseDTO.getExtractedBiometrics())) {
throw new BiometricExtractionException(INVALID_BIOMETRIC.getErrorCode(),
String.format(INVALID_BIOMETRIC.getErrorMessage()));
}
return bioExtractResponseDTO.getExtractedBiometrics();
}

@@ -171,5 +194,9 @@ private List<BIR> doBioExtraction(List<BIR> birs, Map<String, String> extraction
throws BiometricExtractionException {
return bioExractionHelper.extractTemplates(birs, extractionFormats);
}

private boolean validateCbeff(List<BIR> birs) {
return birs.size() > 0 && birs.stream().allMatch(cbeff -> cbeff.getBdb() != null && cbeff.getBdb().length > 0);
}

}
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
import static io.mosip.idrepository.core.constant.IdRepoErrorConstants.ID_OBJECT_PROCESSING_FAILED;
import static io.mosip.idrepository.core.constant.IdRepoErrorConstants.NO_RECORD_FOUND;
import static io.mosip.idrepository.core.constant.IdRepoErrorConstants.RECORD_EXISTS;
import static io.mosip.idrepository.core.constant.IdRepoErrorConstants.INVALID_BIOMETRIC;

import java.io.IOException;
import java.util.*;
@@ -453,6 +454,10 @@ protected byte[] getBiometricsForRequestedFormats(String uinHash, String fileNam
mosipLogger.error(IdRepoSecurityManager.getUser(), ID_REPO_SERVICE_IMPL, "extractTemplate", e.getMessage());
throw new IdRepoAppException(BIO_EXTRACTION_ERROR, e);
} catch (Exception e) {
ExceptionUtils.getStackTrace(e);
if(e.getMessage().contains(INVALID_BIOMETRIC.getErrorCode())) {
throw new IdRepoAppException(INVALID_BIOMETRIC, e);
}
mosipLogger.error(IdRepoSecurityManager.getUser(), ID_REPO_SERVICE_IMPL, "extractTemplate", e.getMessage());
throw new IdRepoAppException(BIO_EXTRACTION_ERROR, e);
}