From a4ddeed7fe9553ff52e0a758ffcdb88ed78dc538 Mon Sep 17 00:00:00 2001 From: Sk Mijan Hossain Date: Tue, 20 Aug 2024 21:41:42 +0530 Subject: [PATCH] delete ApplicantDetailsController --- .../entity/ApplicantUserDetailsEntity.java | 29 --- .../ApplicantUserDetailsRepository.java | 18 -- .../entity/DigitalCardStatusResponseDto.java | 17 -- .../ApplicantDetailsController.java | 67 ------ .../admin/service/ApplicantDetailService.java | 13 -- .../admin/service/impl/AdminServiceImpl.java | 26 ++- .../impl/ApplicantDetailServiceImpl.java | 207 ------------------ .../admin/util/CbeffToBiometricUtil.java | 137 ------------ 8 files changed, 14 insertions(+), 500 deletions(-) delete mode 100644 admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/ApplicantUserDetailsEntity.java delete mode 100644 admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/ApplicantUserDetailsRepository.java delete mode 100644 admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/DigitalCardStatusResponseDto.java delete mode 100644 admin/admin-service/src/main/java/io/mosip/admin/controller/ApplicantDetailsController.java delete mode 100644 admin/admin-service/src/main/java/io/mosip/admin/service/ApplicantDetailService.java delete mode 100644 admin/admin-service/src/main/java/io/mosip/admin/service/impl/ApplicantDetailServiceImpl.java delete mode 100644 admin/admin-service/src/main/java/io/mosip/admin/util/CbeffToBiometricUtil.java diff --git a/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/ApplicantUserDetailsEntity.java b/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/ApplicantUserDetailsEntity.java deleted file mode 100644 index 053ca5fb964..00000000000 --- a/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/ApplicantUserDetailsEntity.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.mosip.admin.bulkdataupload.entity; - -import lombok.Data; -import org.hibernate.annotations.GenericGenerator; - -import javax.persistence.*; -import java.io.Serializable; -import java.time.LocalDate; - -@Data -@Entity -@Table(name = "applicant_login_detail", schema = "master") -public class ApplicantUserDetailsEntity extends BaseEntity implements Serializable { - - private static final long serialVersionUID = -8541947587557590379L; - - @Id - @GeneratedValue(generator = "uuid") - @GenericGenerator(name = "uuid", strategy = "org.hibernate.id.UUIDGenerator") - @Column(name = "id", nullable = false, length = 64) - private String id; - - @Column(name = "usr_id", nullable = false, length = 64) - private String userId; - - @Column(name = "login_date") - private LocalDate loginDate; - -} diff --git a/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/ApplicantUserDetailsRepository.java b/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/ApplicantUserDetailsRepository.java deleted file mode 100644 index 9621c88a943..00000000000 --- a/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/ApplicantUserDetailsRepository.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.mosip.admin.bulkdataupload.entity; - -import io.mosip.kernel.core.dataaccess.spi.repository.BaseRepository; -import org.springframework.stereotype.Repository; - -import java.time.LocalDate; - -/** - * @author Dhanendra - * - */ -@Repository -public interface ApplicantUserDetailsRepository extends BaseRepository { - - - long countByUserIdAndLoginDate(String userId, LocalDate loginDate); - -} diff --git a/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/DigitalCardStatusResponseDto.java b/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/DigitalCardStatusResponseDto.java deleted file mode 100644 index 3d951223934..00000000000 --- a/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/DigitalCardStatusResponseDto.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.mosip.admin.dto; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class DigitalCardStatusResponseDto { - - private String id; - - private String statusCode; - - private String url; -} diff --git a/admin/admin-service/src/main/java/io/mosip/admin/controller/ApplicantDetailsController.java b/admin/admin-service/src/main/java/io/mosip/admin/controller/ApplicantDetailsController.java deleted file mode 100644 index ec9c15f96ab..00000000000 --- a/admin/admin-service/src/main/java/io/mosip/admin/controller/ApplicantDetailsController.java +++ /dev/null @@ -1,67 +0,0 @@ -package io.mosip.admin.controller; - -import io.mosip.admin.dto.ApplicantDetailsDto; -import io.mosip.admin.dto.ApplicantUserDetailsDto; -import io.mosip.admin.packetstatusupdater.util.AuditUtil; -import io.mosip.admin.packetstatusupdater.util.EventEnum; -import io.mosip.admin.service.ApplicantDetailService; -import io.mosip.kernel.core.http.ResponseWrapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.InputStreamResource; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import java.io.ByteArrayInputStream; - -@RestController -public class ApplicantDetailsController { - - @Autowired - AuditUtil auditUtil; - - @Autowired - ApplicantDetailService applicantDetailService; - - //@PreAuthorize("hasRole('DIGITALCARD_ADMIN')") - @PreAuthorize("hasAnyRole(@authorizedRoles.getGetapplicantDetailsrid())") - @GetMapping("/applicantDetails/{rid}") - public ResponseWrapper getApplicantDetails(@PathVariable("rid") String rid) throws Exception { - auditUtil.setAuditRequestDto(EventEnum.APPLICANT_VERIFICATION_API_CALLED,null); - ResponseWrapper responseWrapper = new ResponseWrapper<>(); - responseWrapper.setResponse(applicantDetailService.getApplicantDetails(rid)); - auditUtil.setAuditRequestDto(EventEnum.APPLICANT_VERIFICATION_SUCCESS,null); - return responseWrapper; - } - - // @PreAuthorize("hasRole('DIGITALCARD_ADMIN')") - @PreAuthorize("hasAnyRole(@authorizedRoles.getGetapplicantDetailsgetLoginDetails())") - @GetMapping("/applicantDetails/getLoginDetails") - public ResponseWrapper getApplicantUserDetails() throws Exception { - auditUtil.setAuditRequestDto(EventEnum.APPLICANT_LOGIN_DETAILS_API_CALLED,null); - ResponseWrapper responseWrapper = new ResponseWrapper<>(); - responseWrapper.setResponse(applicantDetailService.getApplicantUserDetails()); - auditUtil.setAuditRequestDto(EventEnum.APPLICANT_LOGIN_DETAILS_SUCCESS,null); - return responseWrapper; - } - - // @PreAuthorize("hasRole('DIGITALCARD_ADMIN')") - @PreAuthorize("hasAnyRole(@authorizedRoles.getGetriddigitalcardrid())") - @GetMapping("/rid-digital-card/{rid}") - public ResponseEntity getRIDDigitalCard( - @PathVariable("rid") String rid,@RequestParam("isAcknowledged") boolean isAcknowledged) throws Exception { - auditUtil.setAuditRequestDto(EventEnum.RID_DIGITAL_CARD_REQ,null); - - byte[] pdfBytes = applicantDetailService.getRIDDigitalCard(rid,isAcknowledged); - InputStreamResource resource = new InputStreamResource(new ByteArrayInputStream(pdfBytes)); - auditUtil.setAuditRequestDto(EventEnum.RID_DIGITAL_CARD_REQ_SUCCESS,null); - return ResponseEntity.ok().contentType(MediaType.parseMediaType("application/pdf")) - .header("Content-Disposition", "attachment; filename=\"" + - rid + ".pdf\"") - .body((Object) resource); - } -} diff --git a/admin/admin-service/src/main/java/io/mosip/admin/service/ApplicantDetailService.java b/admin/admin-service/src/main/java/io/mosip/admin/service/ApplicantDetailService.java deleted file mode 100644 index 99c896a20a6..00000000000 --- a/admin/admin-service/src/main/java/io/mosip/admin/service/ApplicantDetailService.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.mosip.admin.service; - -import io.mosip.admin.dto.ApplicantDetailsDto; -import io.mosip.admin.dto.ApplicantUserDetailsDto; - -public interface ApplicantDetailService { - - ApplicantDetailsDto getApplicantDetails(String rid) throws Exception; - - byte[] getRIDDigitalCard(String rid, boolean isAcknowledged) throws Exception; - - ApplicantUserDetailsDto getApplicantUserDetails(); -} \ No newline at end of file diff --git a/admin/admin-service/src/main/java/io/mosip/admin/service/impl/AdminServiceImpl.java b/admin/admin-service/src/main/java/io/mosip/admin/service/impl/AdminServiceImpl.java index 92f7cb9b44a..56b3488b337 100644 --- a/admin/admin-service/src/main/java/io/mosip/admin/service/impl/AdminServiceImpl.java +++ b/admin/admin-service/src/main/java/io/mosip/admin/service/impl/AdminServiceImpl.java @@ -39,16 +39,9 @@ public class AdminServiceImpl implements AdminService { @Value("${mosip.registration.processor.lostrid.id:mosip.registration.lostrid}") private String lostRidRequestId; - @Value("${mosip.admin.lostrid.details.fields:firstName,middleName,lastName,dateOfBirth}") + @Value("${mosip.admin.lostrid.details.fields}") private String[] fields; - @Value("${mosip.admin.lostrid.details.name.field:firstName}") - private String firstName; - @Value("${mosip.admin.lostrid.details.name.field:middleName}") - private String middleName; - @Value("${mosip.admin.lostrid.details.name.field:lastName}") - private String lastName; - @Value("${mosip.admin.lostrid.details.biometric.field:individualBiometrics}") private String biometricField; @@ -63,7 +56,6 @@ public class AdminServiceImpl implements AdminService { private static final String VALUE = "value"; private static final Logger logger = LoggerFactory.getLogger(AdminServiceImpl.class); - @Autowired private Utility utility; @@ -140,12 +132,15 @@ public LostRidDetailsDto getLostRidDetails(String rid) { fieldResponseDto = objectMapper.readValue(objectMapper.writeValueAsString(fieldDtosResponseWrapper.getResponse()), SearchFieldResponseDto.class); for (String field: fields) { +// String value = fieldResponseDto.getFields().get(field); String value = fieldResponseDto.getFields().get(field); if(value ==null) continue; + if (fieldResponseDto.getFields().containsKey(field) && isNameFields(field)) { org.json.JSONArray jsonArray = new org.json.JSONArray(value); org.json.JSONObject jsonObject = (org.json.JSONObject) jsonArray.get(0); - lostRidDataMap.put(field, jsonObject.getString(VALUE)); + + lostRidDataMap.put(field, jsonObject.get(VALUE).toString()); } else { lostRidDataMap.put(field, fieldResponseDto.getFields().get(field)); @@ -163,8 +158,15 @@ public LostRidDetailsDto getLostRidDetails(String rid) { return lostRidDetailsDto; } - private boolean isNameFields(String field){ - return field.equalsIgnoreCase(firstName) ||field.equalsIgnoreCase(middleName)||field.equalsIgnoreCase(lastName); + boolean isNameFields(String field){ + for (String nameField : fields) { + // Check if the current nameField is not "dateOfBirth" + if (!nameField.equalsIgnoreCase("dateOfBirth") && field.equalsIgnoreCase(nameField)) { + return true; + } + } + // Return false if no match found or if the field is "dateOfBirth" + return false; } private void getApplicantPhoto(String rid, Map lostRidDataMap){ diff --git a/admin/admin-service/src/main/java/io/mosip/admin/service/impl/ApplicantDetailServiceImpl.java b/admin/admin-service/src/main/java/io/mosip/admin/service/impl/ApplicantDetailServiceImpl.java deleted file mode 100644 index b37790e84ed..00000000000 --- a/admin/admin-service/src/main/java/io/mosip/admin/service/impl/ApplicantDetailServiceImpl.java +++ /dev/null @@ -1,207 +0,0 @@ -package io.mosip.admin.service.impl; - -import com.fasterxml.jackson.databind.ObjectMapper; -import io.mosip.admin.bulkdataupload.entity.ApplicantUserDetailsEntity; -import io.mosip.admin.bulkdataupload.entity.ApplicantUserDetailsRepository; -import io.mosip.admin.constant.ApplicantDetailErrorCode; -import io.mosip.admin.dto.ApplicantDetailsDto; -import io.mosip.admin.dto.ApplicantUserDetailsDto; -import io.mosip.admin.dto.DigitalCardStatusResponseDto; -import io.mosip.admin.packetstatusupdater.constant.ApiName; - -import io.mosip.admin.packetstatusupdater.exception.DataNotFoundException; -import io.mosip.admin.packetstatusupdater.exception.MasterDataServiceException; -import io.mosip.admin.packetstatusupdater.exception.RequestException; -import io.mosip.admin.packetstatusupdater.util.AuditUtil; -import io.mosip.admin.packetstatusupdater.util.EventEnum; -import io.mosip.admin.packetstatusupdater.util.RestClient; -import io.mosip.admin.service.ApplicantDetailService; -import io.mosip.admin.util.CbeffToBiometricUtil; -import io.mosip.admin.util.Utility; -import io.mosip.biometrics.util.ConvertRequestDto; -import io.mosip.biometrics.util.face.FaceDecoder; -import io.mosip.kernel.core.idvalidator.exception.InvalidIDException; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.codec.binary.StringUtils; -import org.json.JSONException; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.stereotype.Service; -import org.springframework.web.client.ResourceAccessException; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.*; - -@Service -public class ApplicantDetailServiceImpl implements ApplicantDetailService { - - private static final String FACE = "Face"; - - @Autowired - RestClient restClient; - - @Autowired - private ObjectMapper objectMapper; - - @Autowired - private AuditUtil auditUtil; - - @Autowired - CbeffToBiometricUtil cbeffToBiometricUtil; - - - @Autowired - Utility utility; - - @Autowired - private ApplicantUserDetailsRepository applicantUserDetailsRepository; - - private static final String IDENTITY = "identity"; - - private static final String RESPONSE = "response"; - - private static final String AVAILABLE = "available"; - - private static final String DOCUMENTS="documents"; - - private static final String ApplicantPhoto = "applicantPhoto"; - - private static final String VALUE = "value"; - private static final String DOB = "dob"; - - @Value("${mosip.admin.applicant-details.exposed-identity-fields}") - private String[] applicantDetails; - - @Value("${mosip.admin.applicant-details.max.login.count:15}") - private int maxcount; - - - @Override - public ApplicantDetailsDto getApplicantDetails(String rid) throws Exception { - ApplicantDetailsDto applicantDetailsDto =new ApplicantDetailsDto(); - Map applicantDataMap=new HashMap<>(); - List pathsegments=new ArrayList<>(); - String individualBiometrics=null; - pathsegments.add(rid); - String imageData=null; - try { - String userId = ((UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername(); - long count=applicantUserDetailsRepository.countByUserIdAndLoginDate(userId, LocalDate.now()); - if((int)count>=maxcount){ - throw new RequestException(ApplicantDetailErrorCode.LIMIT_EXCEEDED.getErrorCode(), - ApplicantDetailErrorCode.LIMIT_EXCEEDED.getErrorMessage()); - } - String response = restClient.getApi(ApiName.RETRIEVE_IDENTITY_API,pathsegments,"type","bio",String.class); - JSONObject responseObj= objectMapper.readValue(response,JSONObject.class); - if(response!=null && responseObj.get("response")==null) { - throw new RequestException(ApplicantDetailErrorCode.RID_NOT_FOUND.getErrorCode(), - ApplicantDetailErrorCode.RID_NOT_FOUND.getErrorMessage()); - } - JSONObject responseJsonObj= utility.getJSONObject(responseObj,RESPONSE); - JSONObject identityObj=utility.getJSONObject(responseJsonObj,IDENTITY); - JSONArray documents=utility.getJSONArray(responseJsonObj,DOCUMENTS); - String idenitityJson=utility.getMappingJson(); - JSONObject idenitityJsonObject=objectMapper.readValue(idenitityJson,JSONObject.class); - JSONObject mapperIdentity=utility.getJSONObject(idenitityJsonObject,IDENTITY); - List mapperJsonKeys = new ArrayList<>(mapperIdentity.keySet()); - for(String valueObj: applicantDetails){ - if(valueObj!=null && !valueObj.equalsIgnoreCase(ApplicantPhoto)){ - LinkedHashMap jsonObject = utility.getJSONValue(mapperIdentity, valueObj); - String value = jsonObject.get(VALUE); - applicantDataMap.put(value,identityObj.get(value).toString()); - } else if (valueObj.equalsIgnoreCase(ApplicantPhoto)) { - getImageData(documents,applicantDataMap); - } - } - saveApplicantLoginDetails(); - applicantDetailsDto.setApplicantDataMap(applicantDataMap); - } catch (ResourceAccessException | JSONException e) { - auditUtil.setAuditRequestDto(EventEnum.APPLICANT_VERIFICATION_ERROR,null); - throw new RequestException(ApplicantDetailErrorCode.UNABLE_TO_RETRIEVE_RID_DETAILS.getErrorCode(), - ApplicantDetailErrorCode.UNABLE_TO_RETRIEVE_RID_DETAILS.getErrorMessage(),e); - }catch (InvalidIDException | DataNotFoundException e){ - auditUtil.setAuditRequestDto(EventEnum.APPLICANT_VERIFICATION_ERROR,null); - throw new RequestException(e.getErrorCode(), e.getErrorText()); - } - return applicantDetailsDto; - } - - @Override - public byte[] getRIDDigitalCard(String rid, boolean isAcknowledged) throws Exception { - if(!isAcknowledged){ - throw new MasterDataServiceException( - ApplicantDetailErrorCode.DIGITAL_CARD_NOT_ACKNOWLEDGED.getErrorCode(), - ApplicantDetailErrorCode.DIGITAL_CARD_NOT_ACKNOWLEDGED.getErrorMessage()); - } - DigitalCardStatusResponseDto digitalCardStatusResponseDto =getDigitialCardStatus(rid); - if(!digitalCardStatusResponseDto.getStatusCode().equalsIgnoreCase(AVAILABLE)) { - auditUtil.setAuditRequestDto(EventEnum.RID_DIGITAL_CARD_REQ_EXCEPTION,null); - throw new MasterDataServiceException( - ApplicantDetailErrorCode.DIGITAL_CARD_RID_NOT_FOUND.getErrorCode(), - ApplicantDetailErrorCode.DIGITAL_CARD_RID_NOT_FOUND.getErrorMessage()); - } - return restClient.getApi(digitalCardStatusResponseDto.getUrl(), byte[].class); - } - - @Override - public ApplicantUserDetailsDto getApplicantUserDetails() { - String userId = ((UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername(); - ApplicantUserDetailsDto applicantUserDetailsDto=new ApplicantUserDetailsDto(); - applicantUserDetailsDto.setMaxCount(maxcount); - long count=applicantUserDetailsRepository.countByUserIdAndLoginDate(userId,LocalDate.now()); - applicantUserDetailsDto.setCount((int)count); - return applicantUserDetailsDto; - } - - private DigitalCardStatusResponseDto getDigitialCardStatus(String rid) - throws Exception { - - List pathsegments=new ArrayList<>(); - pathsegments.add(rid); - String response = restClient.getApi(ApiName.DIGITAL_CARD_STATUS_URL,pathsegments,"","",String.class); - JSONObject responseObj= objectMapper.readValue(response,JSONObject.class); - if(responseObj.containsKey("response") && responseObj.get("response")==null) { - throw new MasterDataServiceException(ApplicantDetailErrorCode.REQ_ID_NOT_FOUND.getErrorCode(), - ApplicantDetailErrorCode.REQ_ID_NOT_FOUND.getErrorMessage()); - } - JSONObject responseJsonObj= utility.getJSONObject(responseObj,RESPONSE); - DigitalCardStatusResponseDto digitalCardStatusResponseDto = objectMapper.readValue( - responseJsonObj.toJSONString(), DigitalCardStatusResponseDto.class); - return digitalCardStatusResponseDto; - } - - private void getImageData(JSONArray documents, Map applicantDataMap) throws Exception { - ConvertRequestDto convertRequestDto = new ConvertRequestDto(); - JSONObject documentObj=utility.getJSONObjectFromArray(documents,0); - String individualBiometrics = utility.getJSONValue(documentObj, VALUE); - List subtype = new ArrayList<>(); - byte[] photoByte = cbeffToBiometricUtil.getImageBytes(individualBiometrics, FACE, subtype); - if (photoByte != null) { - convertRequestDto.setVersion("ISO19794_5_2011"); - convertRequestDto.setInputBytes(photoByte); - byte[] data = FaceDecoder.convertFaceISOToImageBytes(convertRequestDto); - String encodedBytes = StringUtils.newStringUtf8(Base64.encodeBase64(data, false)); - String imageData = "data:image/png;base64," + encodedBytes; - applicantDataMap.put(ApplicantPhoto, imageData); - } else { - throw new DataNotFoundException(ApplicantDetailErrorCode.DATA_NOT_FOUND.getErrorCode(), ApplicantDetailErrorCode.DATA_NOT_FOUND.getErrorMessage()); - } - } - public void saveApplicantLoginDetails(){ - String userId = ((UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername(); - ApplicantUserDetailsEntity applicantUserDetailsEntity=new ApplicantUserDetailsEntity(); - applicantUserDetailsEntity.setUserId(userId); - applicantUserDetailsEntity.setLoginDate(LocalDate.now()); - applicantUserDetailsEntity.setCreatedBy(SecurityContextHolder.getContext().getAuthentication().getName()); - applicantUserDetailsEntity.setCreatedDateTime(LocalDateTime.now()); - applicantUserDetailsEntity.setIsActive(true); - applicantUserDetailsRepository.save(applicantUserDetailsEntity); - } - -} - diff --git a/admin/admin-service/src/main/java/io/mosip/admin/util/CbeffToBiometricUtil.java b/admin/admin-service/src/main/java/io/mosip/admin/util/CbeffToBiometricUtil.java deleted file mode 100644 index 1948578b97f..00000000000 --- a/admin/admin-service/src/main/java/io/mosip/admin/util/CbeffToBiometricUtil.java +++ /dev/null @@ -1,137 +0,0 @@ -package io.mosip.admin.util; - -import io.mosip.admin.constant.ApplicantDetailErrorCode; -import io.mosip.admin.packetstatusupdater.exception.DataNotFoundException; -import io.mosip.kernel.biometrics.constant.BiometricType; -import io.mosip.kernel.biometrics.entities.BIR; -import io.mosip.kernel.biometrics.spi.CbeffUtil; -import io.mosip.kernel.cbeffutil.impl.CbeffImpl; -import io.mosip.kernel.core.cbeffutil.jaxbclasses.BIRType; -import io.mosip.kernel.core.cbeffutil.jaxbclasses.SingleType; -import org.apache.commons.codec.binary.Base64; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import java.util.List; - -/** - * The Class CbeffToBiometricUtil. - * - * @author M1048358 Alok - * @author M1030448 Jyoti - */ -@Component -public class CbeffToBiometricUtil { - - /** The print logger. */ - private static final Logger logger = LoggerFactory.getLogger(CbeffToBiometricUtil.class); - - - /** The cbeffutil. */ - private CbeffUtil cbeffutil = new CbeffImpl(); - - /** - * Instantiates biometric util - * - */ - public CbeffToBiometricUtil() { - - } - - /** - * Gets the photo. - * - * @param cbeffFileString the cbeff file string - * @param type the type - * @param subType the sub type - * @return the photo - * @throws Exception the exception - */ - public byte[] getImageBytes(String cbeffFileString, String type, List subType) { - logger.debug("CbeffToBiometricUtil::getImageBytes()::entry"); - byte[] photoBytes = null; - if (cbeffFileString != null) { - List bIRTypeList = null; - try { - bIRTypeList = getBIRTypeList(cbeffFileString); - photoBytes = getPhotoByTypeAndSubType(bIRTypeList, type, subType); - } catch (Exception e) { - throw new DataNotFoundException(ApplicantDetailErrorCode.DATA_NOT_FOUND.getErrorCode(),ApplicantDetailErrorCode.DATA_NOT_FOUND.getErrorMessage()); - } - } - logger.debug("CbeffToBiometricUtil::getImageBytes()::exit"); - return photoBytes; - } - - /** - * Gets the photo by type and sub type. - * - * @param type the type - * @param subType the sub type - * @return the photo by type and sub type - */ - private byte[] getPhotoByTypeAndSubType(List bIRList, String type, List subType) { - byte[] photoBytes = null; - for (BIR bir : bIRList) { - if (bir.getBdbInfo() != null) { - List singleTypeList = bir.getBdbInfo().getType(); - List subTypeList = bir.getBdbInfo().getSubtype(); - - boolean isType = isBiometricType(type, singleTypeList); - boolean isSubType = isSubType(subType, subTypeList); - - if (isType && isSubType) { - photoBytes = bir.getBdb(); - break; - } - } - } - return photoBytes; - } - - /** - * Checks if is sub type. - * - * @param subType the sub type - * @param subTypeList the sub type list - * @return true, if is sub type - */ - private boolean isSubType(List subType, List subTypeList) { - return subTypeList.equals(subType) ? Boolean.TRUE : Boolean.FALSE; - } - - private boolean isBiometricType(String type, List biometricTypeList) { - boolean isType = false; - for (BiometricType biometricType : biometricTypeList) { - if (biometricType.value().equalsIgnoreCase(type)) { - isType = true; - } - } - return isType; - } - - - /** - * Gets the BIR type list. - * - * @param cbeffFileString the cbeff file string - * @return the BIR type list - * @throws Exception the exception - */ - - public List getBIRTypeList(String cbeffFileString) throws Exception { - return cbeffutil.getBIRDataFromXML(Base64.decodeBase64(cbeffFileString)); - } - - /** - * Gets the BIR type list. - * - * @param xmlBytes byte array of XML data - * @return the BIR type list - * @throws Exception the exception - */ - public List getBIRDataFromXML(byte[] xmlBytes) throws Exception { - return cbeffutil.getBIRDataFromXML(xmlBytes); - } -}