diff --git a/admin/admin-service/pom.xml b/admin/admin-service/pom.xml index 4025bb68ad1..d19f870118d 100644 --- a/admin/admin-service/pom.xml +++ b/admin/admin-service/pom.xml @@ -49,23 +49,37 @@ ${kernel.version} - commons-io - commons-io - 2.10.0 + commons-io + commons-io + 2.10.0 - 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 + com.fasterxml.jackson.core + jackson-databind + 2.17.1 - + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + 2.15.0 + + + + org.springframework.batch.extensions + spring-batch-excel + 0.1.0 + + + io.mosip.kernel kernel-authcodeflowproxy-api ${kernel.version} @@ -87,10 +101,10 @@ ${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 @@ -98,14 +112,38 @@ - 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 + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + + + + org.hibernate + hibernate-validator + 6.0.13.Final + + + + org.apache.poi + poi + 5.2.2 + + + + javax.xml.bind + jaxb-api + 2.3.1 + + + com.google.code.gson + gson + 2.8.6 org.springframework.boot @@ -127,7 +165,7 @@ io.mosip.kernel kernel-idvalidator-rid ${kernel.version} - + org.springdoc springdoc-openapi-ui @@ -233,86 +271,88 @@ - - -openapi-doc-generate-profile - - - io.mosip.kernel - kernel-auth-adapter - ${kernel-auth-adapter.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 + ${kernel-auth-adapter.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 + - - - - 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 - - - - - - + + + + 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 + + + + + + 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..c073e401d7a --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/constant/ApplicantDetailErrorCode.java @@ -0,0 +1,34 @@ +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..eb91c4c9ceb 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,13 @@ 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..f628bab88fa 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 @@ -4,11 +4,15 @@ import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +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.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.LostRidDetailsDto; import io.mosip.admin.dto.LostRidExtnDto; import io.mosip.admin.dto.LostRidResponseDto; import io.mosip.admin.dto.SearchInfo; @@ -24,22 +28,32 @@ public class AdminController { @Autowired AdminService adminService; - + @Autowired AuditUtil auditUtil; + @PreAuthorize("hasAnyRole(@authorizedRoles.getPostlostRid())") @PostMapping("/lostRid") - private ResponseWrapper lostRid(@RequestBody RequestWrapper searchInfo) { - auditUtil.setAuditRequestDto(EventEnum.LOST_RID_API_CALLED,null); + 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); + auditUtil.setAuditRequestDto(EventEnum.LOST_RID_SUCCESS, null); return buildLostRidResponse(lostRidResponseDto); } - + + @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(); - List sr=new ArrayList<>(); + List sr = new ArrayList<>(); if (!lostRidResponseDto.getErrors().isEmpty()) { for (ErrorDTO ed : lostRidResponseDto.getErrors()) { ServiceError se = new ServiceError(); 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..1e5aad4dee0 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 @@ -27,6 +27,10 @@ public class AuthorizedRolesDto { //packet status update controller private List getpacketstatusupdate; + //admin lostRid controller + private List getlostRiddetailsrid; + private List postlostRid; + // keymanager controller private List getgeneratecsrcertificateapplicationidreferenceid; 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..9d5152451b0 --- /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 java.util.List; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@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..90e1b385e3a --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/dto/LostRidDetailsDto.java @@ -0,0 +1,17 @@ +package io.mosip.admin.dto; + +import java.util.HashMap; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import lombok.Data; + +@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..242f88a107c --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/dto/SearchFieldDtos.java @@ -0,0 +1,18 @@ +package io.mosip.admin.dto; + +import java.util.List; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@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..fec0665cac9 --- /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 java.util.Map; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +@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..e7f8be624f7 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 @@ -7,6 +7,8 @@ */ 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/RestClient.java b/admin/admin-service/src/main/java/io/mosip/admin/packetstatusupdater/util/RestClient.java index ffa4f7594ff..7f460845bfd 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 @@ -8,14 +8,18 @@ import org.springframework.core.env.Environment; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; 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.UriComponentsBuilder; +import io.mosip.admin.constant.ApplicantDetailErrorCode; import io.mosip.admin.packetstatusupdater.constant.ApiName; +import io.mosip.admin.packetstatusupdater.exception.MasterDataServiceException; @@ -96,5 +100,23 @@ private HttpEntity setRequestHeader(Object requestType, MediaType mediaT } else return new HttpEntity<>(headers); } + + @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; + } } 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..a616287d9f9 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,6 @@ public interface AdminService { LostRidResponseDto lostRid(SearchInfo searchInfo); + LostRidDetailsDto getLostRidDetails(String rid); + } 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..e0c885fda8e 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,19 @@ package io.mosip.admin.service.impl; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import io.mosip.admin.dto.*; + +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; @@ -10,11 +21,17 @@ import com.fasterxml.jackson.databind.ObjectMapper; +import io.mosip.admin.constant.ApplicantDetailErrorCode; import io.mosip.admin.constant.LostRidErrorCode; import io.mosip.admin.packetstatusupdater.constant.ApiName; import io.mosip.admin.packetstatusupdater.exception.RequestException; import io.mosip.admin.packetstatusupdater.util.RestClient; import io.mosip.admin.service.AdminService; +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 io.mosip.kernel.core.util.DateUtils; @@ -26,12 +43,40 @@ 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 RestClient restClient; @Autowired ObjectMapper objectMapper; + + @Autowired + private Utility utility; @Override @@ -73,5 +118,97 @@ private void createLostRidRequest(SearchInfo searchInfoRequest) { } + 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/util/Utility.java b/admin/admin-service/src/main/java/io/mosip/admin/util/Utility.java new file mode 100644 index 00000000000..e7e32f65cc3 --- /dev/null +++ b/admin/admin-service/src/main/java/io/mosip/admin/util/Utility.java @@ -0,0 +1,77 @@ +package io.mosip.admin.util; + +import java.util.ArrayList; +import java.util.LinkedHashMap; + +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 io.mosip.admin.packetstatusupdater.util.RestClient; +import io.mosip.kernel.core.util.StringUtils; + +@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; + } + +}