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 updated 1.1.5.5 #1797

Merged
merged 8 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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,21 +1,22 @@
package io.mosip.registration.processor.abis.handler.dto;

import io.mosip.registration.processor.core.common.rest.dto.BaseRestResponseDTO;
import io.mosip.registration.processor.core.common.rest.dto.ErrorDTO;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

@Data
@EqualsAndHashCode(callSuper = true)
public class DataShareResponseDto extends BaseRestResponseDTO {

private static final long serialVersionUID = 1L;


private DataShare dataShare;


private List<ErrorDTO> errors;
}
package io.mosip.registration.processor.abis.handler.dto;

import java.util.List;

import io.mosip.registration.processor.core.common.rest.dto.BaseRestResponseDTO;
import io.mosip.registration.processor.core.common.rest.dto.ErrorDTO;
import io.mosip.registration.processor.core.packet.dto.abis.DataShare;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class DataShareResponseDto extends BaseRestResponseDTO {

private static final long serialVersionUID = 1L;


private DataShare dataShare;


private List<ErrorDTO> errors;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package io.mosip.registration.processor.abis.handler.stage;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;

import org.apache.commons.lang3.exception.ExceptionUtils;
Expand All @@ -21,13 +17,6 @@
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;

import io.mosip.kernel.biometrics.constant.BiometricType;
import io.mosip.kernel.biometrics.entities.BIR;
import io.mosip.kernel.biometrics.entities.BiometricRecord;
import io.mosip.kernel.core.cbeffutil.spi.CbeffUtil;
import io.mosip.kernel.core.logger.spi.Logger;
Expand All @@ -36,12 +25,7 @@
import io.mosip.kernel.core.util.exception.JsonProcessingException;
import io.mosip.registration.processor.abis.handler.constant.AbisHandlerStageConstant;
import io.mosip.registration.processor.abis.handler.dto.DataShareResponseDto;
import io.mosip.registration.processor.abis.handler.dto.Filter;
import io.mosip.registration.processor.abis.handler.dto.ShareableAttributes;
import io.mosip.registration.processor.abis.handler.dto.Source;
import io.mosip.registration.processor.abis.handler.exception.AbisHandlerException;
import io.mosip.registration.processor.abis.handler.exception.BiometricRecordValidationException;
import io.mosip.registration.processor.abis.handler.exception.DataShareException;
import io.mosip.registration.processor.abis.queue.dto.AbisQueueDetails;
import io.mosip.registration.processor.core.abstractverticle.MessageBusAddress;
import io.mosip.registration.processor.core.abstractverticle.MessageDTO;
Expand All @@ -57,12 +41,11 @@
import io.mosip.registration.processor.core.code.RegistrationTransactionStatusCode;
import io.mosip.registration.processor.core.constant.LoggerFileConstant;
import io.mosip.registration.processor.core.constant.MappingJsonConstants;
import io.mosip.registration.processor.core.constant.PolicyConstant;
import io.mosip.registration.processor.core.constant.ProviderStageName;
import io.mosip.registration.processor.core.exception.ApisResourceAccessException;
import io.mosip.registration.processor.core.exception.BiometricRecordValidationException;
import io.mosip.registration.processor.core.exception.DataShareException;
import io.mosip.registration.processor.core.exception.util.PlatformErrorMessages;
import io.mosip.registration.processor.core.exception.util.PlatformSuccessMessages;
import io.mosip.registration.processor.core.http.ResponseWrapper;
import io.mosip.registration.processor.core.logger.LogDescription;
import io.mosip.registration.processor.core.logger.RegProcessorLogger;
import io.mosip.registration.processor.core.packet.dto.Identity;
Expand All @@ -80,6 +63,7 @@
import io.mosip.registration.processor.core.status.util.TrimExceptionMessage;
import io.mosip.registration.processor.core.util.JsonUtil;
import io.mosip.registration.processor.packet.storage.dto.ApplicantInfoDto;
import io.mosip.registration.processor.packet.storage.utils.ABISHandlerUtil;
import io.mosip.registration.processor.packet.storage.utils.BIRConverter;
import io.mosip.registration.processor.packet.storage.utils.PriorityBasedPacketManagerService;
import io.mosip.registration.processor.packet.storage.utils.Utilities;
Expand Down Expand Up @@ -168,6 +152,10 @@ public class AbisHandlerStage extends MosipVerticleAPIManager {
private static final String DATASHARECREATEURL = "DATASHARECREATEURL";

private static final String DATETIME_PATTERN = "mosip.registration.processor.datetime.pattern";

@Autowired
private ABISHandlerUtil abisHandlerUtil;

/**
* Deploy verticle.
*/
Expand Down Expand Up @@ -556,7 +544,7 @@ private String getUUID() {
}

private String getDataShareUrl(String id, String process) throws Exception {
Map<String,List<String>> typeAndSubtypMap=createTypeSubtypeMapping();
Map<String, List<String>> typeAndSubtypMap = abisHandlerUtil.createBiometricTypeSubtypeMappingFromAbispolicy();
List<String> modalities=new ArrayList<>();
for(Map.Entry<String,List<String>> entry:typeAndSubtypMap.entrySet()) {
if(entry.getValue()==null) {
Expand All @@ -571,7 +559,7 @@ private String getDataShareUrl(String id, String process) throws Exception {
MappingJsonConstants.VALUE);
BiometricRecord biometricRecord = priorityBasedPacketManagerService.getBiometrics(
id, individualBiometricsLabel, modalities, process, ProviderStageName.BIO_DEDUPE);
validateBiometricRecord(biometricRecord, modalities);
abisHandlerUtil.validateBiometricRecord(biometricRecord, modalities);
byte[] content = cbeffutil.createXML(BIRConverter.convertSegmentsToBIRList(biometricRecord.getSegments()));

MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
Expand All @@ -596,77 +584,6 @@ public String getFilename() {

return response.getDataShare().getUrl();
}
public Map<String, List<String>> createTypeSubtypeMapping() throws ApisResourceAccessException, DataShareException, JsonParseException, JsonMappingException, com.fasterxml.jackson.core.JsonProcessingException, IOException{
Map<String, List<String>> typeAndSubTypeMap = new HashMap<>();
ResponseWrapper<?> policyResponse = (ResponseWrapper<?>) registrationProcessorRestClientService.getApi(
ApiName.PMS, Lists.newArrayList(policyId, PolicyConstant.PARTNER_ID, subscriberId), "", "", ResponseWrapper.class);
if (policyResponse == null || (policyResponse.getErrors() != null && policyResponse.getErrors().size() >0)) {
throw new DataShareException(policyResponse == null ? "Policy Response response is null" : policyResponse.getErrors().get(0).getMessage());

} else {
LinkedHashMap<String, Object> responseMap = (LinkedHashMap<String, Object>) policyResponse.getResponse();
LinkedHashMap<String, Object> policies = (LinkedHashMap<String, Object>) responseMap.get(PolicyConstant.POLICIES);
List<?> attributes = (List<?>) policies.get(PolicyConstant.SHAREABLE_ATTRIBUTES);
ObjectMapper mapper = new ObjectMapper();
ShareableAttributes shareableAttributes = mapper.readValue(mapper.writeValueAsString(attributes.get(0)),
ShareableAttributes.class);
for (Source source : shareableAttributes.getSource()) {
List<Filter> filterList = source.getFilter();
if (filterList != null && !filterList.isEmpty()) {

filterList.forEach(filter -> {
if (filter.getSubType() != null && !filter.getSubType().isEmpty()) {
typeAndSubTypeMap.put(filter.getType(), filter.getSubType());
} else {
typeAndSubTypeMap.put(filter.getType(), null);
}
});
}
}
}
return typeAndSubTypeMap;

}

private void validateBiometricRecord(BiometricRecord biometricRecord, List<String> modalities)
throws BiometricRecordValidationException, JsonParseException, JsonMappingException, IOException {
if (modalities == null || modalities.isEmpty()) {
throw new BiometricRecordValidationException(PlatformErrorMessages.RPR_DATASHARE_MODALITIES_EMPTY.getCode(),PlatformErrorMessages.RPR_DATASHARE_MODALITIES_EMPTY.getMessage());
}
if (biometricRecord == null || biometricRecord.getSegments() == null
|| biometricRecord.getSegments().isEmpty()) {
throw new BiometricRecordValidationException(PlatformErrorMessages.RPR_NO_BIOMETRICS_FOUND_WITH_DATASHARE.getCode(),PlatformErrorMessages.RPR_NO_BIOMETRICS_FOUND_WITH_DATASHARE.getMessage());
}

for (String segment : modalities) {
Optional<BIR> optionalBIR = Optional.empty();
if (segment.equalsIgnoreCase("Face")) {
optionalBIR = biometricRecord.getSegments().stream()
.filter(bir -> bir.getBdbInfo().getType() != null
&& bir.getBdbInfo().getType().get(0).equals(BiometricType.FACE))
.findFirst();
} else {
String[] segmentArray = segment.split(" ");
optionalBIR = biometricRecord.getSegments().stream().filter(bir -> bir.getBdbInfo()
.getSubtype() != null && bir.getBdbInfo().getSubtype().size() == segmentArray.length
? (bir.getBdbInfo().getSubtype().get(0).equalsIgnoreCase(segmentArray[0])
&& (segmentArray.length == 2
? bir.getBdbInfo().getSubtype().get(1)
.equalsIgnoreCase(segmentArray[1])
: true))
: false)
.findFirst();
}
if (optionalBIR.isPresent()) {
BIR bir = optionalBIR.get();
if (bir.getBdb() != null) {
return;
}
}
}

throw new BiometricRecordValidationException(
PlatformErrorMessages.RPR_NO_BIOMETRIC_MATCH_WTIH_DATASAHRE.getCode(),
PlatformErrorMessages.RPR_NO_BIOMETRIC_MATCH_WTIH_DATASAHRE.getMessage());
}
}
Loading