From f3c61f7c101aca6eb251733e81f2f1b7b5ea5260 Mon Sep 17 00:00:00 2001 From: mijan32 Date: Mon, 24 Jun 2024 09:54:23 +0530 Subject: [PATCH] lost rid --- admin/admin-service/pom.xml | 301 ++++++++++-------- .../entity/ApplicantUserDetailsEntity.java | 29 ++ .../ApplicantUserDetailsRepository.java | 18 ++ .../entity/DigitalCardStatusResponseDto.java | 17 + .../constant/ApplicantDetailErrorCode.java | 32 ++ .../admin/constant/LostRidErrorCode.java | 6 +- .../admin/controller/AdminController.java | 29 +- .../ApplicantDetailsController.java | 67 ++++ .../mosip/admin/dto/ApplicantDetailsDto.java | 15 + .../admin/dto/ApplicantUserDetailsDto.java | 11 + .../mosip/admin/dto/AuthorizedRolesDto.java | 19 +- .../mosip/admin/dto/BiometricRequestDto.java | 19 ++ .../io/mosip/admin/dto/LostRidDetailsDto.java | 15 + .../io/mosip/admin/dto/SearchFieldDtos.java | 17 + .../admin/dto/SearchFieldResponseDto.java | 17 + .../packetstatusupdater/constant/ApiName.java | 6 +- .../packetstatusupdater/util/AuditUtil.java | 2 +- .../packetstatusupdater/util/EventEnum.java | 146 +++++---- .../packetstatusupdater/util/RestClient.java | 161 +++++++++- .../io/mosip/admin/service/AdminService.java | 2 + .../admin/service/ApplicantDetailService.java | 13 + .../admin/service/impl/AdminServiceImpl.java | 146 ++++++++- .../impl/ApplicantDetailServiceImpl.java | 207 ++++++++++++ .../admin/util/CbeffToBiometricUtil.java | 137 ++++++++ .../java/io/mosip/admin/util/Utility.java | 78 +++++ 25 files changed, 1290 insertions(+), 220 deletions(-) create mode 100644 admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/ApplicantUserDetailsEntity.java create mode 100644 admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/ApplicantUserDetailsRepository.java create mode 100644 admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/DigitalCardStatusResponseDto.java create mode 100644 admin/admin-service/src/main/java/io/mosip/admin/constant/ApplicantDetailErrorCode.java create mode 100644 admin/admin-service/src/main/java/io/mosip/admin/controller/ApplicantDetailsController.java create mode 100644 admin/admin-service/src/main/java/io/mosip/admin/dto/ApplicantDetailsDto.java create mode 100644 admin/admin-service/src/main/java/io/mosip/admin/dto/ApplicantUserDetailsDto.java create mode 100644 admin/admin-service/src/main/java/io/mosip/admin/dto/BiometricRequestDto.java create mode 100644 admin/admin-service/src/main/java/io/mosip/admin/dto/LostRidDetailsDto.java create mode 100644 admin/admin-service/src/main/java/io/mosip/admin/dto/SearchFieldDtos.java create mode 100644 admin/admin-service/src/main/java/io/mosip/admin/dto/SearchFieldResponseDto.java create mode 100644 admin/admin-service/src/main/java/io/mosip/admin/service/ApplicantDetailService.java create mode 100644 admin/admin-service/src/main/java/io/mosip/admin/service/impl/ApplicantDetailServiceImpl.java create mode 100644 admin/admin-service/src/main/java/io/mosip/admin/util/CbeffToBiometricUtil.java create mode 100644 admin/admin-service/src/main/java/io/mosip/admin/util/Utility.java diff --git a/admin/admin-service/pom.xml b/admin/admin-service/pom.xml index d0c11f5aed8..81de6db9cc1 100644 --- a/admin/admin-service/pom.xml +++ b/admin/admin-service/pom.xml @@ -1,8 +1,8 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 io.mosip.admin @@ -11,7 +11,7 @@ admin-service admin-service - 1.2.0.1 + 1.2.0.1-SNAPSHOT http://maven.apache.org jar @@ -25,47 +25,60 @@ io.mosip.kernel kernel-core ${kernel.version} - - - org.apache.logging.log4j - log4j-to-slf4j - - - org.apache.logging.log4j - log4j-api - - + + + + com.fasterxml.jackson.core + jackson-databind + 2.17.1 + + org.projectlombok lombok ${lombok.version} compile + - io.mosip.kernel - kernel-openid-bridge-api - ${kernel.version} + org.hibernate + hibernate-validator + 6.0.13.Final + - commons-io - commons-io - 2.10.0 + org.apache.poi + poi + 5.2.2 - org.apache.poi - poi-ooxml - 5.2.2 + org.apache.poi + poi-ooxml + 5.2.2 - - org.springframework.batch.extensions - spring-batch-excel - 0.1.0 + commons-io + commons-io + 2.10.0 - - - io.mosip.kernel + + + org.springframework.batch.extensions + spring-batch-excel + 0.1.0 + + + + + + org.apache.logging.log4j + log4j-api + 2.17.2 + + + + io.mosip.kernel kernel-authcodeflowproxy-api ${kernel.version} @@ -73,6 +86,7 @@ io.mosip.kernel kernel-core + @@ -86,25 +100,29 @@ ${spring-cloud-config.version} - org.springframework.boot - spring-boot-starter-batch - ${spring.boot.version} - + org.springframework.boot + spring-boot-starter-batch + ${spring.boot.version} + org.postgresql postgresql ${postgresql.version} - - javax.xml.bind - jaxb-api - 2.3.1 - - - com.google.code.gson - gson - 2.8.6 + io.mosip.biometric.util + biometrics-util + 1.2.0.2 + + + javax.xml.bind + jaxb-api + 2.3.1 + + + com.google.code.gson + gson + 2.8.6 org.springframework.boot @@ -126,7 +144,7 @@ io.mosip.kernel kernel-idvalidator-rid ${kernel.version} - + org.springdoc springdoc-openapi-ui @@ -138,11 +156,30 @@ + + io.mosip.kernel + kernel-auth-adapter + 1.2.0.1 + + + org.springframework.boot + spring-boot-starter-webflux + + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + + + io.mosip.commons commons-packet-manager - 1.2.0.1-SNAPSHOT + ${kernel.version} org.springframework.cloud @@ -160,10 +197,6 @@ org.springframework.boot spring-boot-starter-security - - io.vertx - vertx-web - io.mosip.kernel kernel-auth-adapter @@ -172,6 +205,11 @@ io.mosip.kernel kernel-logger-logback + + io.vertx + vertx-web + + @@ -209,86 +247,87 @@ - - -openapi-doc-generate-profile - - - io.mosip.kernel - kernel-auth-adapter - ${project.version} - - - io.netty - netty-transport - 4.1.72.Final - - - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring.boot.version} - - true - ZIP - - - - pre-integration-test - - start - - - - src/test/resources - - - test - - - --server.port=8090 - --server.servlet.context-path=/app/generic - + + + openapi-doc-generate-profile + + + io.mosip.kernel + kernel-auth-adapter + ${project.version} + + + io.netty + netty-transport + 4.1.72.Final + - - - - post-integration-test - - stop - - - - - build-info - repackage - - - - - - org.springdoc - springdoc-openapi-maven-plugin - 0.2 - - - integration-test - - generate - - - - - http://localhost:8090/app/generic/v3/api-docs/Admin%20Service - ${artifactId}-openapi.json - ${project.build.directory} - false - - - - - - - + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + true + ZIP + + + + pre-integration-test + + start + + + + src/test/resources + + + test + + + --server.port=8090 + --server.servlet.context-path=/app/generic + + + + + + post-integration-test + + stop + + + + + build-info + repackage + + + + + + org.springdoc + springdoc-openapi-maven-plugin + 0.2 + + + integration-test + + generate + + + + + http://localhost:8090/app/generic/v3/api-docs/Admin%20Service + ${artifactId}-openapi.json + ${project.build.directory} + false + + + + + + + \ No newline at end of file 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 new file mode 100644 index 00000000000..053ca5fb964 --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/ApplicantUserDetailsEntity.java @@ -0,0 +1,29 @@ +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 new file mode 100644 index 00000000000..9621c88a943 --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/ApplicantUserDetailsRepository.java @@ -0,0 +1,18 @@ +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 new file mode 100644 index 00000000000..3d951223934 --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/bulkdataupload/entity/DigitalCardStatusResponseDto.java @@ -0,0 +1,17 @@ +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/constant/ApplicantDetailErrorCode.java b/admin/admin-service/src/main/java/io/mosip/admin/constant/ApplicantDetailErrorCode.java new file mode 100644 index 00000000000..03fdf29a1c5 --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/constant/ApplicantDetailErrorCode.java @@ -0,0 +1,32 @@ +package io.mosip.admin.constant; + +public enum ApplicantDetailErrorCode { + + UNABLE_TO_RETRIEVE_RID_DETAILS("ADM-AVD-001", "A technical error occurred while retrieving the data, please try again after some time."), + RID_INVALID("ADM-AVD-002","RID is invalid"), + RID_NOT_FOUND("ADM-AVD-003","The card for this request ID is not generated. Please check the status of the ID."), + DATA_NOT_FOUND("ADM-AVD-004","Applicant Photo Not Found"), + DIGITAL_CARD_RID_NOT_FOUND("ADM-AVD-005", "Digital card not found for the RID, please try after few days"), + DIGITAL_CARD_NOT_ACKNOWLEDGED("ADM-AVD-006", "Please acknowledge the details before downloading digital card"), + REQ_ID_NOT_FOUND("ADM-AVD-007","Request id not found"), + + LIMIT_EXCEEDED("ADM-AVD-008","Your daily search limit has exceeded. Please try searching again tomorrow."), + + DATA_SHARE_EXPIRED_EXCEPTION("ADM-AVD-008", "Data share usuage expired"); + + private final String errorCode; + private final String errorMessage; + + private ApplicantDetailErrorCode(final String errorCode, final String errorMessage) { + this.errorCode = errorCode; + this.errorMessage = errorMessage; + } + + public String getErrorCode() { + return errorCode; + } + + public String getErrorMessage() { + return errorMessage; + } +} diff --git a/admin/admin-service/src/main/java/io/mosip/admin/constant/LostRidErrorCode.java b/admin/admin-service/src/main/java/io/mosip/admin/constant/LostRidErrorCode.java index a4f66e1a0bb..70894d37397 100644 --- a/admin/admin-service/src/main/java/io/mosip/admin/constant/LostRidErrorCode.java +++ b/admin/admin-service/src/main/java/io/mosip/admin/constant/LostRidErrorCode.java @@ -2,7 +2,11 @@ public enum LostRidErrorCode { - UNABLE_TO_RETRIEVE_LOSTRID("ADMN-LRID-001", "Unable ro find the lost rid.."); + UNABLE_TO_RETRIEVE_LOSTRID("ADMN-LRID-001", "Unable to find the lost rid.."), + UNABLE_TO_RETRIEVE_LOSTRID_DATA("ADMN-LRID-002", "Unable to find the lost rid data"), + + UNABLE_TO_RETRIEVE_APPLICANT_PHOTO("ADMN-LRID-003", "Unable to retrieve applicantPhoto"); + private final String errorCode; private final String errorMessage; diff --git a/admin/admin-service/src/main/java/io/mosip/admin/controller/AdminController.java b/admin/admin-service/src/main/java/io/mosip/admin/controller/AdminController.java index f473f74d01d..7c45c57c9fa 100644 --- a/admin/admin-service/src/main/java/io/mosip/admin/controller/AdminController.java +++ b/admin/admin-service/src/main/java/io/mosip/admin/controller/AdminController.java @@ -3,15 +3,11 @@ import java.util.ArrayList; import java.util.List; +import io.mosip.admin.dto.*; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; - -import io.mosip.admin.dto.ErrorDTO; -import io.mosip.admin.dto.LostRidExtnDto; -import io.mosip.admin.dto.LostRidResponseDto; -import io.mosip.admin.dto.SearchInfo; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + import io.mosip.admin.packetstatusupdater.util.AuditUtil; import io.mosip.admin.packetstatusupdater.util.EventEnum; import io.mosip.admin.service.AdminService; @@ -24,18 +20,29 @@ public class AdminController { @Autowired AdminService adminService; - + @Autowired AuditUtil auditUtil; + @PreAuthorize("hasAnyRole(@authorizedRoles.getPostlostRid())") @PostMapping("/lostRid") - private ResponseWrapper lostRid(@RequestBody RequestWrapper searchInfo) { + public ResponseWrapper lostRid(@RequestBody RequestWrapper searchInfo) { auditUtil.setAuditRequestDto(EventEnum.LOST_RID_API_CALLED,null); LostRidResponseDto lostRidResponseDto = adminService.lostRid(searchInfo.getRequest()); auditUtil.setAuditRequestDto(EventEnum.LOST_RID_SUCCESS,null); return buildLostRidResponse(lostRidResponseDto); } - + +// @PreAuthorize("hasAnyRole(@authorizedRoles.getGetlostRiddetailsrid())") + @GetMapping("/lostRid/details/{rid}") + public ResponseWrapper getLostRidDetails(@PathVariable("rid") String rid) { + auditUtil.setAuditRequestDto(EventEnum.LOST_RID_API_CALLED,null); + ResponseWrapper responseWrapper = new ResponseWrapper<>(); + responseWrapper.setResponse(adminService.getLostRidDetails(rid)); + auditUtil.setAuditRequestDto(EventEnum.LOST_RID_SUCCESS,null); + return responseWrapper; + } + private ResponseWrapper buildLostRidResponse(LostRidResponseDto lostRidResponseDto) { ResponseWrapper responseWrapper = new ResponseWrapper<>(); LostRidExtnDto lostRidExtnDto = new LostRidExtnDto(); 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 new file mode 100644 index 00000000000..ec9c15f96ab --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/controller/ApplicantDetailsController.java @@ -0,0 +1,67 @@ +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/dto/ApplicantDetailsDto.java b/admin/admin-service/src/main/java/io/mosip/admin/dto/ApplicantDetailsDto.java new file mode 100644 index 00000000000..a05fa15c444 --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/dto/ApplicantDetailsDto.java @@ -0,0 +1,15 @@ +package io.mosip.admin.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +import java.util.HashMap; +import java.util.Map; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class ApplicantDetailsDto { + + Map applicantDataMap=new HashMap<>(); + +} diff --git a/admin/admin-service/src/main/java/io/mosip/admin/dto/ApplicantUserDetailsDto.java b/admin/admin-service/src/main/java/io/mosip/admin/dto/ApplicantUserDetailsDto.java new file mode 100644 index 00000000000..2168a073875 --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/dto/ApplicantUserDetailsDto.java @@ -0,0 +1,11 @@ +package io.mosip.admin.dto; + +import lombok.Data; + +@Data +public class ApplicantUserDetailsDto { + + private int maxCount; + + private int count; +} diff --git a/admin/admin-service/src/main/java/io/mosip/admin/dto/AuthorizedRolesDto.java b/admin/admin-service/src/main/java/io/mosip/admin/dto/AuthorizedRolesDto.java index 69072fe85ed..af25b3ed62c 100644 --- a/admin/admin-service/src/main/java/io/mosip/admin/dto/AuthorizedRolesDto.java +++ b/admin/admin-service/src/main/java/io/mosip/admin/dto/AuthorizedRolesDto.java @@ -16,9 +16,9 @@ public class AuthorizedRolesDto { //Bulk data upload controller private List postbulkupload; - + private List getbulkuploadtranscationtranscationid; - + private List getbulkuploadgetalltransactions; //Audit manager proxy controller @@ -26,13 +26,22 @@ public class AuthorizedRolesDto { //packet status update controller private List getpacketstatusupdate; - - + + //admin lostRid controller + + private List getlostRiddetailsrid; + private List postlostRid; + + //applicant Details controller + + private List getapplicantDetailsrid; + private List getapplicantDetailsgetLoginDetails; + private List getriddigitalcardrid; // keymanager controller private List getgeneratecsrcertificateapplicationidreferenceid; private List postuploadcertificate; private List postgeneratecsr; private List postuploadotherdomaincertificate; - + } \ No newline at end of file diff --git a/admin/admin-service/src/main/java/io/mosip/admin/dto/BiometricRequestDto.java b/admin/admin-service/src/main/java/io/mosip/admin/dto/BiometricRequestDto.java new file mode 100644 index 00000000000..3a66a746c9c --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/dto/BiometricRequestDto.java @@ -0,0 +1,19 @@ +package io.mosip.admin.dto; + + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +@Data +@EqualsAndHashCode +public class BiometricRequestDto { + + private String id; + private String person; + private List modalities; + private String source; + private String process; + private boolean bypassCache; +} diff --git a/admin/admin-service/src/main/java/io/mosip/admin/dto/LostRidDetailsDto.java b/admin/admin-service/src/main/java/io/mosip/admin/dto/LostRidDetailsDto.java new file mode 100644 index 00000000000..8523d7888d0 --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/dto/LostRidDetailsDto.java @@ -0,0 +1,15 @@ +package io.mosip.admin.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +import java.util.HashMap; +import java.util.Map; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class LostRidDetailsDto { + + Map lostRidDataMap=new HashMap<>(); + +} diff --git a/admin/admin-service/src/main/java/io/mosip/admin/dto/SearchFieldDtos.java b/admin/admin-service/src/main/java/io/mosip/admin/dto/SearchFieldDtos.java new file mode 100644 index 00000000000..563dcf44279 --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/dto/SearchFieldDtos.java @@ -0,0 +1,17 @@ +package io.mosip.admin.dto; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +@Data +@EqualsAndHashCode +public class SearchFieldDtos { + + private String id; + private List fields; + private String source; + private String process; + private Boolean bypassCache; +} diff --git a/admin/admin-service/src/main/java/io/mosip/admin/dto/SearchFieldResponseDto.java b/admin/admin-service/src/main/java/io/mosip/admin/dto/SearchFieldResponseDto.java new file mode 100644 index 00000000000..d13ccfe0519 --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/dto/SearchFieldResponseDto.java @@ -0,0 +1,17 @@ +package io.mosip.admin.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +import java.util.Map; + +@Data +@EqualsAndHashCode +@AllArgsConstructor +@NoArgsConstructor +public class SearchFieldResponseDto { + + Map fields; +} diff --git a/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/constant/ApiName.java b/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/constant/ApiName.java index 14788bdd01f..d9175e2be34 100644 --- a/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/constant/ApiName.java +++ b/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/constant/ApiName.java @@ -1,12 +1,14 @@ package io.mosip.admin.packetstatusupdater.constant; /** - * + * * @author Sowmya * */ public enum ApiName { - LOST_RID_API,CRYPTOMANAGERDECRYPT_API,MACHINE_GET_API; + LOST_RID_API,CRYPTOMANAGERDECRYPT_API,MACHINE_GET_API,RETRIEVE_IDENTITY_API,DIGITAL_CARD_STATUS_URL, + + PACKET_MANAGER_BIOMETRIC,PACKET_MANAGER_SEARCHFIELDS; } diff --git a/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/util/AuditUtil.java b/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/util/AuditUtil.java index 89fa4044e7f..1a98ce49428 100644 --- a/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/util/AuditUtil.java +++ b/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/util/AuditUtil.java @@ -200,7 +200,7 @@ public void setAuditRequestDto(EventEnum eventEnum, String username) { //if current profile is local or dev donot call this method if(Arrays.stream(env.getActiveProfiles().length == 0 ? env.getDefaultProfiles() : env.getActiveProfiles()).anyMatch( - environment -> (environment.equalsIgnoreCase("local") || + environment -> (environment.equalsIgnoreCase("local1") || environment.equalsIgnoreCase("test")) )) { LOGGER.info("Recieved Audit : {}",auditRequestDto.toString()); } else { diff --git a/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/util/EventEnum.java b/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/util/EventEnum.java index a021636c443..564ab7d81b1 100644 --- a/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/util/EventEnum.java +++ b/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/util/EventEnum.java @@ -4,9 +4,9 @@ import io.mosip.admin.packetstatusupdater.dto.PacketStatusUpdateDto; public enum EventEnum { - - - USER_NOT_AUTHORIZED("ADM-PKT-405",AuditConstant.AUDIT_USER,"Authorization request","User %s is not authorized","ADM-PKT","Packet service","NO_ID","NO_ID_TYPE",AuditConstant.APPLICATION_ID,AuditConstant.APPLICATION_NAME), + + + USER_NOT_AUTHORIZED("ADM-PKT-405",AuditConstant.AUDIT_USER,"Authorization request","User %s is not authorized","ADM-PKT","Packet service","NO_ID","NO_ID_TYPE",AuditConstant.APPLICATION_ID,AuditConstant.APPLICATION_NAME), RID_INVALID("ADM-PKT-406",AuditConstant.AUDIT_USER,"Check RID validation","Registration id is invalid","ADM-PKT","Packet service","NO_ID","NO_ID_TYPE",AuditConstant.APPLICATION_ID,AuditConstant.APPLICATION_NAME), CENTRE_NOT_EXISTS("ADM-PKT-407",AuditConstant.AUDIT_USER,"Check centre exists","Centre id extracted from registration id does not exists","ADM-PKT","Packet service","NO_ID","NO_ID_TYPE",AuditConstant.APPLICATION_ID,AuditConstant.APPLICATION_NAME), RID_MISS("ADM-PKT-408",AuditConstant.AUDIT_USER,"Check RID exists","Registration id is missing in the input","ADM-PKT","Packet service","NO_ID","NO_ID_TYPE",AuditConstant.APPLICATION_ID,AuditConstant.APPLICATION_NAME), @@ -39,7 +39,7 @@ public enum EventEnum { BULKDATA_OPERATION_ERROR("ADM-BLK-402",AuditConstant.AUDIT_SYSTEM,"Request for bulkdata operation","Error occured while operating bulk data for %s","ADM-BLK","Bulk data service","NO_ID","NO_ID_TYPE",AuditConstant.APPLICATION_ID,AuditConstant.APPLICATION_NAME), BULKDATA_OPERATION_CSV_EXT_VALIDATOR_ISSUE("ADM-BLK-403",AuditConstant.AUDIT_SYSTEM,"Validating CSV file request","%s is not csv file","ADM-BLK","Bulk data service","NO_ID","NO_ID_TYPE",AuditConstant.APPLICATION_ID,AuditConstant.APPLICATION_NAME), BULKDATA_OPERATION_INVALID_CSV_FILE("ADM-BLK-404",AuditConstant.AUDIT_SYSTEM,"Validating CSV file request","Invalid csv file %s","ADM-BLK","Bulk data service","NO_ID","NO_ID_TYPE",AuditConstant.APPLICATION_ID,AuditConstant.APPLICATION_NAME), - BULKDATA_OPERATION_CSV_VALIDATOR_ISSUE("ADM-BLK-405",AuditConstant.AUDIT_SYSTEM,"Validating CSV file request","All the rows have same number of element in csv file %s","ADM-BLK","Bulk data service","NO_ID","NO_ID_TYPE",AuditConstant.APPLICATION_ID,AuditConstant.APPLICATION_NAME), + BULKDATA_OPERATION_CSV_VALIDATOR_ISSUE("ADM-BLK-405",AuditConstant.AUDIT_SYSTEM,"Validating CSV file request","All the rows have same number of element in csv file %s","ADM-BLK","Bulk data service","NO_ID","NO_ID_TYPE",AuditConstant.APPLICATION_ID,AuditConstant.APPLICATION_NAME), BULKDATA_UPLOAD_CSV_STATUS("ADM-BLK-106",AuditConstant.AUDIT_SYSTEM,"Request for bulkdata insert operation based on category","Status of inserting file %s","ADM-BLK","Bulk data service","NO_ID","NO_ID_TYPE",AuditConstant.APPLICATION_ID,AuditConstant.APPLICATION_NAME), BULKDATA_UPLOAD_TRANSACTION_API_CALLED("ADM-BLK-107",AuditConstant.AUDIT_SYSTEM,"Request for bulkdata upload transaction","Inserting data into transaction table based on %s","ADM-BLK","Bulk data service","NO_ID","NO_ID_TYPE",AuditConstant.APPLICATION_ID,AuditConstant.APPLICATION_NAME), BULKDATA_UPLOAD_TRANSACTION_API_SUCCESS("ADM-BLK-108",AuditConstant.AUDIT_SYSTEM,"Request for bulkdata upload transaction","Successfully inserted data into transaction table with transaction id %s","ADM-BLK","Bulk data service","%s","Transaction Id",AuditConstant.APPLICATION_ID,AuditConstant.APPLICATION_NAME), @@ -83,27 +83,47 @@ public enum EventEnum { ADMIN_PROXY_ERROR("ADM-MSD-411",AuditConstant.AUDIT_SYSTEM,"Request for Admin Proxy","Failed to call Rest api - %s","ADM-MSD","Admin Proxy service","NO_ID","NO_ID_TYPE",AuditConstant.APPLICATION_ID,AuditConstant.APPLICATION_NAME), KEYMANAGER_PROXY_API_CALLED("ADM-MSD-410", AuditConstant.AUDIT_SYSTEM, "Request for KeyManager proxy API", "API called for KeyManager proxy", "ADM-MSD", "Admin Proxy service", "NO_ID", "NO_ID_TYPE", - AuditConstant.APPLICATION_ID, AuditConstant.APPLICATION_NAME ); + AuditConstant.APPLICATION_ID, AuditConstant.APPLICATION_NAME ), + APPLICANT_VERIFICATION_API_CALLED("ADM-AVD-501", AuditConstant.AUDIT_SYSTEM, "Request for Applicant Verification API", + "API called for Applicant Verification request", "ADM-AVD", "Admin service", "NO_ID", "NO_ID_TYPE", + AuditConstant.APPLICATION_ID, AuditConstant.APPLICATION_NAME), + APPLICANT_VERIFICATION_SUCCESS("ADM-AVD-502", AuditConstant.AUDIT_SYSTEM, "Request for Applicant Verification API", + "successfully return the applicantPhoto and dob", "ADM-AVD", "admin service", "NO_ID", "NO_ID_TYPE", + AuditConstant.APPLICATION_ID, AuditConstant.APPLICATION_NAME), + APPLICANT_VERIFICATION_ERROR("ADM-AVD-503",AuditConstant.AUDIT_SYSTEM,"Request for Applicant Verification","Failed to call Rest api - %s","ADM-AVD","admin service","NO_ID","NO_ID_TYPE",AuditConstant.APPLICATION_ID,AuditConstant.APPLICATION_NAME), + RID_DIGITAL_CARD_REQ_EXCEPTION("ADM-AVD-504",AuditConstant.AUDIT_SYSTEM,"Request for Digital Card","Downloading digital card based on RID failed - %s","ADM-AVD","admin service","NO_ID","NO_ID_TYPE",AuditConstant.APPLICATION_ID,AuditConstant.APPLICATION_NAME), + RID_DIGITAL_CARD_REQ("ADM-AVD-505", AuditConstant.AUDIT_SYSTEM, "Request for Digital Card", + "API called for Digital card", "ADM-AVD", "Admin service", "NO_ID", "NO_ID_TYPE", + AuditConstant.APPLICATION_ID, AuditConstant.APPLICATION_NAME), + RID_DIGITAL_CARD_REQ_SUCCESS("ADM-AVD-506", AuditConstant.AUDIT_SYSTEM, "Request for Digital Card", + "successfully returned the digital card", "ADM-AVD", "admin service", "NO_ID", "NO_ID_TYPE", + AuditConstant.APPLICATION_ID, AuditConstant.APPLICATION_NAME), + APPLICANT_LOGIN_DETAILS_API_CALLED("ADM-AVD-507", AuditConstant.AUDIT_SYSTEM, "Request for Applicant Login Details API", + "API called for Applicant Login Details", "ADM-AVD", "Admin service", "NO_ID", "NO_ID_TYPE", + AuditConstant.APPLICATION_ID, AuditConstant.APPLICATION_NAME), + APPLICANT_LOGIN_DETAILS_SUCCESS("ADM-AVD-508", AuditConstant.AUDIT_SYSTEM, "Request for Applicant Login Details API", + "successfully return the login details", "ADM-AVD", "admin service", "NO_ID", "NO_ID_TYPE", + AuditConstant.APPLICATION_ID, AuditConstant.APPLICATION_NAME); + - private final String eventId; private final String type; - + private final String name; private String description; - + private String moduleId; - + private String moduleName; - + private String id; - + private String idType; - + private final String applicationId; - + private final String applicationName; private EventEnum(String eventId, String type, String name, String description,String moduleId,String moduleName,String id,String idType,String applicationId,String applicationName) { @@ -119,8 +139,8 @@ private EventEnum(String eventId, String type, String name, String description,S this.applicationName=applicationName; } - - + + public String getId() { return id; } @@ -138,7 +158,7 @@ public String getEventId() { public String getType() { return type; } - + public void setId(String id) { this.id=id; } @@ -154,7 +174,7 @@ public void setDescription(String description) { public String getName() { return name; } - + public String getModuleId() { return moduleId; } @@ -162,8 +182,8 @@ public String getModuleId() { public String getModuleName() { return moduleName; } - - + + public String getApplicationId() { return applicationId; @@ -180,51 +200,51 @@ public String getApplicationName() { public static EventEnum getEventEnumBasedOnPAcketStatus(PacketStatusUpdateDto ps) { if(null!=ps.getTransactionTypeCode()) { - if(ps.getTransactionTypeCode().equalsIgnoreCase("PACKET_RECEIVER")) - { - if(null==ps.getParentTransactionId() || ps.getParentTransactionId().isBlank()) - return getEventEnumWithValue(PACKET_RECEIVER,ps.getRegistrationId()); - return getEventEnumWithValue(PACKET_RECEIVER_WITH_TRANS_CODE,ps.getRegistrationId()); + if(ps.getTransactionTypeCode().equalsIgnoreCase("PACKET_RECEIVER")) + { + if(null==ps.getParentTransactionId() || ps.getParentTransactionId().isBlank()) + return getEventEnumWithValue(PACKET_RECEIVER,ps.getRegistrationId()); + return getEventEnumWithValue(PACKET_RECEIVER_WITH_TRANS_CODE,ps.getRegistrationId()); + } + if(ps.getTransactionTypeCode().equalsIgnoreCase("UPLOAD_PACKET")) + return getEventEnumWithValue(UPLOAD_PACKET,ps.getRegistrationId()); + if(ps.getTransactionTypeCode().equalsIgnoreCase("PRINT_SERVICE")) + return getEventEnumWithValue(PRINT_SERVICE,ps.getRegistrationId()); + if(ps.getTransactionTypeCode().equalsIgnoreCase("PRINT_POSTAL_SERVICE")) + return getEventEnumWithValue(PRINT_POSTAL_SERVICE,ps.getRegistrationId()); + if(ps.getTransactionTypeCode().equalsIgnoreCase("VIRUS_SCAN")) + return getEventEnumWithValue(VIRUS_SCAN,ps.getRegistrationId()); + if(ps.getTransactionTypeCode().equalsIgnoreCase("VALIDATE_PACKET")) + return getEventEnumWithValue(VALIDATE_PACKET,ps.getRegistrationId()); + if(ps.getTransactionTypeCode().equalsIgnoreCase("OSI_VALIDATE")) + return getEventEnumWithValue(OSI_VALIDATE,ps.getRegistrationId()); + if(ps.getTransactionTypeCode().equalsIgnoreCase("EXTERNAL_INTEGRATION")) + return getEventEnumWithValue(EXTERNAL_INTEGRATION,ps.getRegistrationId()); + if(ps.getTransactionTypeCode().equalsIgnoreCase("DEMOGRAPHIC_VERIFICATION")) + return getEventEnumWithValue(DEMOGRAPHIC_VERIFICATION,ps.getRegistrationId()); + if(ps.getTransactionTypeCode().equalsIgnoreCase("MANUAL_VERIFICATION")) + return getEventEnumWithValue(MANUAL_VERIFICATION,ps.getRegistrationId()); + if(ps.getTransactionTypeCode().equalsIgnoreCase("BIOGRAPHIC_VERIFICATION")) + return getEventEnumWithValue(BIOGRAPHIC_VERIFICATION,ps.getRegistrationId()); + if(ps.getTransactionTypeCode().equalsIgnoreCase("UIN_GENERATOR")) + return getEventEnumWithValue(UIN_GENERATOR,ps.getRegistrationId()); + if(ps.getTransactionTypeCode().equalsIgnoreCase("NOTIFICATION")) + return getEventEnumWithValue(NOTIFICATION,ps.getRegistrationId()); + if(ps.getTransactionTypeCode().equalsIgnoreCase("PACKET_REPROCESS")) + return getEventEnumWithValue(PACKET_REPROCESS,ps.getRegistrationId()); + if(ps.getTransactionTypeCode().equalsIgnoreCase("QUALITY_CHECK")) + return getEventEnumWithValue(QUALITY_CHECK,ps.getRegistrationId()); + if(ps.getTransactionTypeCode().equalsIgnoreCase("BIOMETRIC_AUTHENTICATION")) + return getEventEnumWithValue(BIOMETRIC_AUTHENTICATION,ps.getRegistrationId()); + if(ps.getTransactionTypeCode().equalsIgnoreCase("SECUREZONE_NOTIFICATION")) + return getEventEnumWithValue(SECUREZONE_NOTIFICATION,ps.getRegistrationId()); + if(ps.getTransactionTypeCode().equalsIgnoreCase("PRINT")) + return getEventEnumWithValue(PRINT,ps.getRegistrationId()); } - if(ps.getTransactionTypeCode().equalsIgnoreCase("UPLOAD_PACKET")) - return getEventEnumWithValue(UPLOAD_PACKET,ps.getRegistrationId()); - if(ps.getTransactionTypeCode().equalsIgnoreCase("PRINT_SERVICE")) - return getEventEnumWithValue(PRINT_SERVICE,ps.getRegistrationId()); - if(ps.getTransactionTypeCode().equalsIgnoreCase("PRINT_POSTAL_SERVICE")) - return getEventEnumWithValue(PRINT_POSTAL_SERVICE,ps.getRegistrationId()); - if(ps.getTransactionTypeCode().equalsIgnoreCase("VIRUS_SCAN")) - return getEventEnumWithValue(VIRUS_SCAN,ps.getRegistrationId()); - if(ps.getTransactionTypeCode().equalsIgnoreCase("VALIDATE_PACKET")) - return getEventEnumWithValue(VALIDATE_PACKET,ps.getRegistrationId()); - if(ps.getTransactionTypeCode().equalsIgnoreCase("OSI_VALIDATE")) - return getEventEnumWithValue(OSI_VALIDATE,ps.getRegistrationId()); - if(ps.getTransactionTypeCode().equalsIgnoreCase("EXTERNAL_INTEGRATION")) - return getEventEnumWithValue(EXTERNAL_INTEGRATION,ps.getRegistrationId()); - if(ps.getTransactionTypeCode().equalsIgnoreCase("DEMOGRAPHIC_VERIFICATION")) - return getEventEnumWithValue(DEMOGRAPHIC_VERIFICATION,ps.getRegistrationId()); - if(ps.getTransactionTypeCode().equalsIgnoreCase("MANUAL_VERIFICATION")) - return getEventEnumWithValue(MANUAL_VERIFICATION,ps.getRegistrationId()); - if(ps.getTransactionTypeCode().equalsIgnoreCase("BIOGRAPHIC_VERIFICATION")) - return getEventEnumWithValue(BIOGRAPHIC_VERIFICATION,ps.getRegistrationId()); - if(ps.getTransactionTypeCode().equalsIgnoreCase("UIN_GENERATOR")) - return getEventEnumWithValue(UIN_GENERATOR,ps.getRegistrationId()); - if(ps.getTransactionTypeCode().equalsIgnoreCase("NOTIFICATION")) - return getEventEnumWithValue(NOTIFICATION,ps.getRegistrationId()); - if(ps.getTransactionTypeCode().equalsIgnoreCase("PACKET_REPROCESS")) - return getEventEnumWithValue(PACKET_REPROCESS,ps.getRegistrationId()); - if(ps.getTransactionTypeCode().equalsIgnoreCase("QUALITY_CHECK")) - return getEventEnumWithValue(QUALITY_CHECK,ps.getRegistrationId()); - if(ps.getTransactionTypeCode().equalsIgnoreCase("BIOMETRIC_AUTHENTICATION")) - return getEventEnumWithValue(BIOMETRIC_AUTHENTICATION,ps.getRegistrationId()); - if(ps.getTransactionTypeCode().equalsIgnoreCase("SECUREZONE_NOTIFICATION")) - return getEventEnumWithValue(SECUREZONE_NOTIFICATION,ps.getRegistrationId()); - if(ps.getTransactionTypeCode().equalsIgnoreCase("PRINT")) - return getEventEnumWithValue(PRINT,ps.getRegistrationId()); - } return null; - + } - + public static EventEnum getEventEnumWithValue(EventEnum e,String s) { e.setDescription(String.format(e.getDescription(),s)); @@ -232,6 +252,6 @@ public static EventEnum getEventEnumWithValue(EventEnum e,String s) e.setId(s); return e; } - - + + } diff --git a/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/util/RestClient.java b/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/util/RestClient.java index ffa4f7594ff..4525e6fbd1c 100644 --- a/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/util/RestClient.java +++ b/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/util/RestClient.java @@ -4,15 +4,16 @@ import java.util.Iterator; import java.util.List; +import io.mosip.admin.constant.ApplicantDetailErrorCode; +import io.mosip.admin.packetstatusupdater.exception.MasterDataServiceException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; +import org.springframework.http.*; import org.springframework.stereotype.Component; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; import io.mosip.admin.packetstatusupdater.constant.ApiName; @@ -20,7 +21,7 @@ /** - * + * * @author Dhanendra * */ @@ -63,7 +64,157 @@ public T postApi(ApiName apiName, MediaType mediaType, Object requestType, C return result; } - /** + /** + * Post api. + * + * @param the generic type + * @param apiName the api name + * @param pathsegments the pathsegments + * @param queryParamName the query param name + * @param queryParamValue the query param value + * @param mediaType the media type + * @param requestType the request type + * @param responseClass the response class + * @return the t + * @throws Exception + */ + @SuppressWarnings("unchecked") + public T postApi(ApiName apiName, List pathsegments, String queryParamName, String queryParamValue, + MediaType mediaType, Object requestType, Class responseClass) throws Exception { + T result = null; + String apiHostIpPort = environment.getProperty(apiName.name()); + UriComponentsBuilder builder = null; + if (apiHostIpPort != null) + builder = UriComponentsBuilder.fromUriString(apiHostIpPort); + if (builder != null) { + + if (!((pathsegments == null) || (pathsegments.isEmpty()))) { + for (String segment : pathsegments) { + if (!((segment == null) || (("").equals(segment)))) { + builder.pathSegment(segment); + } + } + + } + if (!((queryParamName == null) || (("").equals(queryParamName)))) { + String[] queryParamNameArr = queryParamName.split(","); + String[] queryParamValueArr = queryParamValue.split(","); + + for (int i = 0; i < queryParamNameArr.length; i++) { + builder.queryParam(queryParamNameArr[i], queryParamValueArr[i]); + } + } + try { + result = (T) restTemplate.postForObject(builder.toUriString(), setRequestHeader(requestType, mediaType), + responseClass); + } catch (Exception e) { + throw new Exception(e); + } + } + return result; + } + + /** + * Gets the api. + * + * @param the generic type + * @param apiName the api name + * @param pathsegments the pathsegments + * @param queryParamName the query param name + * @param queryParamValue the query param value + * @param responseType the response type + * @return the api + * @throws Exception + */ + @SuppressWarnings("unchecked") + public T getApi(ApiName apiName, List pathsegments, String queryParamName, String queryParamValue, + Class responseType) throws Exception { + + String apiHostIpPort = environment.getProperty(apiName.name()); + T result = null; + UriComponentsBuilder builder = null; + UriComponents uriComponents = null; + if (apiHostIpPort != null) { + + builder = UriComponentsBuilder.fromUriString(apiHostIpPort); + if (!((pathsegments == null) || (pathsegments.isEmpty()))) { + for (String segment : pathsegments) { + if (!((segment == null) || (("").equals(segment)))) { + builder.pathSegment(segment); + } + } + } + if (!((queryParamName == null) || (("").equals(queryParamName)))) { + + String[] queryParamNameArr = queryParamName.split(","); + String[] queryParamValueArr = queryParamValue.split(","); + for (int i = 0; i < queryParamNameArr.length; i++) { + builder.queryParam(queryParamNameArr[i], queryParamValueArr[i]); + } + } + uriComponents = builder.build(false).encode(); + try { + result = (T) restTemplate + .exchange(uriComponents.toUri(), HttpMethod.GET, setRequestHeader(null, null), responseType) + .getBody(); + } catch (Exception e) { + throw new Exception(e); + } + + } + return result; + } + /* *//** + * Gets the Object. + * + * @param the generic type + * @param url the url + * @param responseType the response type + * @return the api + * @throws Exception + *//* + @SuppressWarnings("unchecked") + public T getForObject(String url, + Class responseType) throws Exception { + + T result = null; + try { + result= (T) restTemplate + .getForObject(url, responseType); + } catch (Exception e) { + throw new Exception(e); + } + return result; + }*/ + + /** + * Gets the Object. + * + * @param the generic type + * @param url the url + * @param responseType the response type + * @return the api + * @throws Exception + */ + @SuppressWarnings("unchecked") + public T getApi(String url, + Class responseType) throws Exception { + + T result = null; + try { + ResponseEntity responseEntity= (ResponseEntity) restTemplate + .exchange(url, HttpMethod.GET, setRequestHeader(null, null), responseType); + if(url.contains("datashare") && responseEntity.getHeaders().getContentType().equals(MediaType.APPLICATION_JSON)){ + throw new MasterDataServiceException(ApplicantDetailErrorCode.DATA_SHARE_EXPIRED_EXCEPTION.getErrorCode(), + ApplicantDetailErrorCode.DATA_SHARE_EXPIRED_EXCEPTION.getErrorMessage()); + } + result= (T) responseEntity.getBody(); + } catch (Exception e) { + throw new Exception(e); + } + return result; + } + /** * Sets the request header. * * @param requestType the request type diff --git a/admin/admin-service/src/main/java/io/mosip/admin/service/AdminService.java b/admin/admin-service/src/main/java/io/mosip/admin/service/AdminService.java index 905c40393ce..93666f4483b 100644 --- a/admin/admin-service/src/main/java/io/mosip/admin/service/AdminService.java +++ b/admin/admin-service/src/main/java/io/mosip/admin/service/AdminService.java @@ -1,5 +1,6 @@ package io.mosip.admin.service; +import io.mosip.admin.dto.LostRidDetailsDto; import io.mosip.admin.dto.LostRidResponseDto; import io.mosip.admin.dto.SearchInfo; @@ -8,4 +9,5 @@ public interface AdminService { LostRidResponseDto lostRid(SearchInfo searchInfo); + LostRidDetailsDto getLostRidDetails(String rid); } 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 new file mode 100644 index 00000000000..99c896a20a6 --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/service/ApplicantDetailService.java @@ -0,0 +1,13 @@ +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 ed7b7bac536..92f7cb9b44a 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 @@ -1,8 +1,20 @@ package io.mosip.admin.service.impl; -import java.util.List; +import java.util.*; +import io.mosip.admin.constant.ApplicantDetailErrorCode; import io.mosip.admin.dto.*; +import io.mosip.admin.util.Utility; +import io.mosip.biometrics.util.ConvertRequestDto; +import io.mosip.biometrics.util.face.FaceDecoder; +import io.mosip.kernel.core.http.RequestWrapper; +import io.mosip.kernel.core.http.ResponseWrapper; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.codec.binary.StringUtils; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.MediaType; @@ -27,6 +39,35 @@ 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}") + 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; + + private static final String PROCESS = "NEW"; + + private static final String SOURCE = "REGISTRATION_CLIENT"; + + private static final String RESPONSE = "response"; + + private static final String SEGEMENTS = "segments"; + + private static final String VALUE = "value"; + + private static final Logger logger = LoggerFactory.getLogger(AdminServiceImpl.class); + + @Autowired + private Utility utility; + + @Autowired RestClient restClient; @@ -73,5 +114,108 @@ private void createLostRidRequest(SearchInfo searchInfoRequest) { } + public String getApplicantPhoto(byte[] isodata) throws Exception { + ConvertRequestDto convertRequestDto = new ConvertRequestDto(); + convertRequestDto.setVersion("ISO19794_5_2011"); + convertRequestDto.setInputBytes(isodata); + byte[] data = FaceDecoder.convertFaceISOToImageBytes(convertRequestDto); + String encodedBytes = new String(data); + + return encodedBytes; + } + + @Override + public LostRidDetailsDto getLostRidDetails(String rid) { + LostRidDetailsDto lostRidDetailsDto=new LostRidDetailsDto(); + Map lostRidDataMap=new HashMap<>(); + SearchFieldDtos fieldDtos=new SearchFieldDtos(); + RequestWrapper fieldDtosRequestWrapper=new RequestWrapper<>(); + ConvertRequestDto convertRequestDto = new ConvertRequestDto(); + try { + SearchFieldResponseDto fieldResponseDto=new SearchFieldResponseDto(); + buildSearchFieldsRequestDto(fieldDtos,rid); + fieldDtosRequestWrapper.setRequest(fieldDtos); + ResponseWrapper fieldDtosResponseWrapper = restClient.postApi(ApiName.PACKET_MANAGER_SEARCHFIELDS, MediaType.APPLICATION_JSON, + fieldDtosRequestWrapper, ResponseWrapper.class); + fieldResponseDto = objectMapper.readValue(objectMapper.writeValueAsString(fieldDtosResponseWrapper.getResponse()), SearchFieldResponseDto.class); + + for (String field: fields) { + 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)); + } else { + + lostRidDataMap.put(field, fieldResponseDto.getFields().get(field)); + } + } + getApplicantPhoto(rid,lostRidDataMap); + lostRidDetailsDto.setLostRidDataMap(lostRidDataMap); + } catch (Exception e) { + logger.error("error is occured while searching fields",e.getMessage()); + e.printStackTrace(); + throw new RequestException(LostRidErrorCode.UNABLE_TO_RETRIEVE_LOSTRID_DATA.getErrorCode(), + LostRidErrorCode.UNABLE_TO_RETRIEVE_LOSTRID_DATA.getErrorMessage() + , e); + } + return lostRidDetailsDto; + } + + private boolean isNameFields(String field){ + return field.equalsIgnoreCase(firstName) ||field.equalsIgnoreCase(middleName)||field.equalsIgnoreCase(lastName); + } + + private void getApplicantPhoto(String rid, Map lostRidDataMap){ + RequestWrapper biometricRequestDtoRequestWrapper=new RequestWrapper<>(); + BiometricRequestDto biometricRequestDto=new BiometricRequestDto(); + ConvertRequestDto convertRequestDto = new ConvertRequestDto(); + try { + buildBiometricRequestDto(biometricRequestDto,rid); + biometricRequestDtoRequestWrapper.setRequest(biometricRequestDto); + String response = restClient.postApi(ApiName.PACKET_MANAGER_BIOMETRIC, MediaType.APPLICATION_JSON, + biometricRequestDtoRequestWrapper, String.class); + JSONObject responseObj= objectMapper.readValue(response,JSONObject.class); + JSONObject responseJsonObj=utility.getJSONObject(responseObj,RESPONSE); + JSONArray segements=utility.getJSONArray(responseJsonObj,SEGEMENTS); + JSONObject jsonObject=utility.getJSONObjectFromArray(segements,0); + convertRequestDto.setVersion("ISO19794_5_2011"); + convertRequestDto.setInputBytes(Base64.decodeBase64((String) jsonObject.get("bdb"))); + byte[] data = FaceDecoder.convertFaceISOToImageBytes(convertRequestDto); + String encodedBytes = StringUtils.newStringUtf8(Base64.encodeBase64(data, false)); + String imageData = "data:image/png;base64," + encodedBytes; + if(response!=null && responseObj.get("response")==null) { + logger.error("biometric api response is null : {}",response); + throw new RequestException(ApplicantDetailErrorCode.RID_NOT_FOUND.getErrorCode(), + ApplicantDetailErrorCode.RID_NOT_FOUND.getErrorMessage()); + } + lostRidDataMap.put("applicantPhoto",imageData); + } catch (Exception e) { + logger.error("error is occured while getting applicantPhoto",e); + throw new RequestException(LostRidErrorCode.UNABLE_TO_RETRIEVE_APPLICANT_PHOTO.getErrorCode(), + LostRidErrorCode.UNABLE_TO_RETRIEVE_APPLICANT_PHOTO.getErrorMessage() + ,e); + } + } + + private void buildBiometricRequestDto(BiometricRequestDto biometricRequestDto, String rid) { + List modalities=new ArrayList<>(); + biometricRequestDto.setSource(SOURCE); + biometricRequestDto.setId(rid); + biometricRequestDto.setProcess(PROCESS); + biometricRequestDto.setPerson(biometricField); + modalities.add("Face"); + biometricRequestDto.setModalities(modalities); + } + + + private void buildSearchFieldsRequestDto(SearchFieldDtos fieldDtos, String rid) { + fieldDtos.setSource(SOURCE); + fieldDtos.setId(rid); + fieldDtos.setProcess(PROCESS); + fieldDtos.setFields(Arrays.asList(fields)); + fieldDtos.setBypassCache(false); + } } 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 new file mode 100644 index 00000000000..b37790e84ed --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/service/impl/ApplicantDetailServiceImpl.java @@ -0,0 +1,207 @@ +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 new file mode 100644 index 00000000000..1948578b97f --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/util/CbeffToBiometricUtil.java @@ -0,0 +1,137 @@ +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); + } +} diff --git a/admin/admin-service/src/main/java/io/mosip/admin/util/Utility.java b/admin/admin-service/src/main/java/io/mosip/admin/util/Utility.java new file mode 100644 index 00000000000..d8f789d5672 --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/util/Utility.java @@ -0,0 +1,78 @@ +package io.mosip.admin.util; + +import io.mosip.admin.packetstatusupdater.util.RestClient; +import io.mosip.kernel.core.util.StringUtils; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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 javax.annotation.PostConstruct; +import java.util.ArrayList; +import java.util.LinkedHashMap; + +@Component +public class Utility { + + private static final Logger logger = LoggerFactory.getLogger(Utility.class); + + @Value("${mosip.kernel.config.server.file.storage.uri}") + private String configServerFileStorageURL; + + @Value("${mosip.admin.identityMappingJson}") + private String identityJson; + + @Autowired + private RestClient restClient; + + @Autowired + private Environment env; + + private static final String IDENTITY = "identity"; + private static final String VALUE = "value"; + + private static String regProcessorIdentityJson = ""; + + public String getMappingJson() throws Exception { + if (StringUtils.isBlank(regProcessorIdentityJson)) { + regProcessorIdentityJson=restClient.getApi(configServerFileStorageURL + identityJson, String.class); + } + return regProcessorIdentityJson; + } + + @SuppressWarnings("unchecked") + public JSONObject getJSONObject(JSONObject jsonObject, Object key) { + if(jsonObject == null) + return null; + LinkedHashMap identity = (LinkedHashMap) jsonObject.get(key); + return identity != null ? new JSONObject(identity) : null; + } + @SuppressWarnings("unchecked") + public T getJSONValue(JSONObject jsonObject, Object key) { + T value = (T) jsonObject.get(key); + return value; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public JSONArray getJSONArray(JSONObject jsonObject, Object key) { + ArrayList value = (ArrayList) jsonObject.get(key); + if (value == null) + return null; + JSONArray jsonArray = new JSONArray(); + jsonArray.addAll(value); + + return jsonArray; + + } + @SuppressWarnings("rawtypes") + public JSONObject getJSONObjectFromArray(JSONArray jsonObject, int key) { + LinkedHashMap identity = (LinkedHashMap) jsonObject.get(key); + return identity != null ? new JSONObject(identity) : null; + } + + +}