From ee7c6be41027e63186fcd93fd5c5dd7f839a2225 Mon Sep 17 00:00:00 2001 From: Yash S <119652212+yashmsonkusare@users.noreply.github.com> Date: Wed, 17 Apr 2024 16:24:03 +0530 Subject: [PATCH] MOSIP-21009:Added the sonar bug fixes Signed-off-by: Yash S <119652212+yashmsonkusare@users.noreply.github.com> --- .../packetstatusupdater/util/RestClient.java | 11 ++++++++--- .../service/impl/ApplicantDetailServiceImpl.java | 16 ++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) 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 23187f4162e..f7a39cf7bbf 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 @@ -204,9 +204,14 @@ public T getApi(String url, 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()); + MediaType contentType = responseEntity.getHeaders().getContentType(); + if (url.contains("datashare")) { + if (contentType == null) { + throw new NullPointerException("Content type is null"); + } else if (contentType.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) { 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 index b37790e84ed..0f6c5abf0f9 100644 --- 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 @@ -110,12 +110,16 @@ public ApplicantDetailsDto getApplicantDetails(String rid) throws Exception { 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); + if(valueObj!=null) { + if (!valueObj.equalsIgnoreCase(ApplicantPhoto)) { + LinkedHashMap jsonObject = utility.getJSONValue(mapperIdentity, valueObj); + String value = jsonObject.get(VALUE); + applicantDataMap.put(value, identityObj.get(value).toString()); + } else { + getImageData(documents, applicantDataMap); + } + } else { + throw new NullPointerException("valueObj is null"); } } saveApplicantLoginDetails();